Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few issues with the single package targeting commands #3196

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ namespace Microsoft.WinGet.Client.Commands.Common
/// the "install", "uninstall", and "upgrade" commands.
/// </summary>
public abstract class PackageCmdlet : FinderCmdlet
{
{
/// <summary>
/// Initializes a new instance of the <see cref="PackageCmdlet"/> class.
/// </summary>
public PackageCmdlet()
{
// The default match option for single package operations.
this.MatchOption = PSObjects.PSPackageFieldMatchOption.EqualsCaseInsensitive;
}

/// <summary>
/// Gets or sets the package to directly install.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ protected IReadOnlyList<MatchResult> FindPackages(
return GetMatchResults(catalog, options);
}

private static void SetQueryInFindPackagesOptions(
/// <summary>
/// Sets the find package options for a query input.
/// </summary>
/// <param name="options">The options object.</param>
/// <param name="match">The match type.</param>
/// <param name="value">The query value.</param>
protected virtual void SetQueryInFindPackagesOptions(
ref FindPackagesOptions options,
PackageFieldMatchOption match,
string value)
Expand Down Expand Up @@ -161,7 +167,7 @@ private PackageCatalogReference GetPackageCatalogReference(CompositeSearchBehavi
private FindPackagesOptions GetFindPackagesOptions(uint limit)
{
var options = ComObjectFactory.Value.CreateFindPackagesOptions();
SetQueryInFindPackagesOptions(ref options, this.MatchOption, this.QueryAsJoinedString);
this.SetQueryInFindPackagesOptions(ref options, this.MatchOption, this.QueryAsJoinedString);
this.AddAttributedFiltersToFindPackagesOptions(ref options, this.MatchOption);
options.ResultLimit = limit;
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ protected void GetPackageAndExecute(
}
}

/// <summary>
/// Sets the find package options for a query input that is looking for a specific package.
/// </summary>
/// <param name="options">The options object.</param>
/// <param name="match">The match type.</param>
/// <param name="value">The query value.</param>
protected override void SetQueryInFindPackagesOptions(
ref FindPackagesOptions options,
PackageFieldMatchOption match,
string value)
{
foreach (PackageMatchField field in new PackageMatchField[] { PackageMatchField.Id, PackageMatchField.Name, PackageMatchField.Moniker })
{
var selector = ComObjectFactory.Value.CreatePackageMatchFilter();
selector.Field = field;
selector.Value = value ?? string.Empty;
selector.Option = match;
options.Selectors.Add(selector);
}
}

private CatalogPackage GetCatalogPackage(CompositeSearchBehavior behavior)
{
if (this.CatalogPackage != null)
Expand Down