Skip to content

Commit

Permalink
PowerShell does not like collections...
Browse files Browse the repository at this point in the history
Fixed #80
  • Loading branch information
svrooij committed Jun 13, 2024
1 parent 220d330 commit b2d1bbc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Svrooij.WinTuner.CmdLets/Commands/GetWtWin32Apps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke
result = Superseding.Value ? result.Where(x => x.SupersededAppCount > 0).ToList() : result.Where(x => x.SupersededAppCount == 0).ToList();
}

WriteObject(result);
foreach (var item in result)
{
WriteObject(item);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Svrooij.PowerShell.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -15,7 +16,7 @@ namespace Svrooij.WinTuner.CmdLets.Commands;
/// <code>Search-WtWinGetPackage fire</code>
/// </example>
[Cmdlet(VerbsCommon.Search, "WtWinGetPackage", HelpUri = "https://wintuner.app/docs/wintuner-powershell/Search-WtWingetPackage")]
[OutputType(typeof(Winget.CommunityRepository.Models.WingetEntry[]))]
[OutputType(typeof(IReadOnlyCollection<Winget.CommunityRepository.Models.WingetEntry>))]
public class SearchWtWinGetPackage : DependencyCmdlet<Startup>
{
/// <summary>
Expand All @@ -41,6 +42,9 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke
}
var packages = await wingetRepository.SearchPackage(PackageId ?? throw new ArgumentNullException(nameof(PackageId)), cancellationToken);

WriteObject(packages);
foreach (var package in packages)
{
WriteObject(package);
}
}
}
2 changes: 1 addition & 1 deletion src/WingetIntune/Models/PackageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PackageInfo
;
}

internal bool InstallersLoaded => Installers?.Any() == true;
internal bool InstallersLoaded => Installers?.Count > 0 == true;

public static PackageInfo Parse(string wingetOutput)
{
Expand Down
8 changes: 8 additions & 0 deletions tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ Describe 'Search-WtWinGetPackage' {
$_.PackageId | Should -Match '(?i)Firef'
}
}

It 'Should allow filtering outputs' {
$packages = Search-WtWinGetPackage 'Microsoft.Visual'
$packageFiltered = Search-WtWinGetPackage 'Microsoft.Visual' | Where-Object { $_.PackageId -eq 'Microsoft.VisualStudioCode' }

$packages.Count | Should -BeGreaterThan $packageFiltered.Count
$packageFiltered.Count | Should -Be 1
}
}

0 comments on commit b2d1bbc

Please sign in to comment.