winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 3e3dede932841ec848f27b374b8c8fed45f1a90b
parent 84d3e87847edcd9faa3985f6b84a099d95c913bd
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Fri, 28 Apr 2023 11:00:11 -0700

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


Diffstat:
Msrc/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/PackageCmdlet.cs | 11++++++++++-
Msrc/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/FinderCommand.cs | 10++++++++--
Msrc/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/PackageCommand.cs | 21+++++++++++++++++++++
3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/PackageCmdlet.cs b/src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/PackageCmdlet.cs @@ -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> diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/FinderCommand.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/FinderCommand.cs @@ -88,7 +88,13 @@ namespace Microsoft.WinGet.Client.Engine.Commands.Common 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) @@ -161,7 +167,7 @@ namespace Microsoft.WinGet.Client.Engine.Commands.Common 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; diff --git a/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/PackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client.Engine/Commands/Common/PackageCommand.cs @@ -63,6 +63,27 @@ namespace Microsoft.WinGet.Client.Engine.Commands.Common } } + /// <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)