From 7f46ed1ed0c26c8ecaceb06c505b366467bfe266 Mon Sep 17 00:00:00 2001 From: Jonathan Abbott Date: Tue, 12 Jul 2022 12:27:25 -0700 Subject: [PATCH] Changed version logic; exact behavior; and attached all results to vague criteria error. --- .../Commands/BaseFinderCommand.cs | 2 +- .../Commands/BaseLifecycleCommand.cs | 21 ++++++++++--------- .../Commands/InstallPackageCommand.cs | 1 - .../Commands/UpdatePackageCommand.cs | 1 - .../Resources/Resources.Designer.cs | 9 ++++++++ .../Resources/Resources.resx | 3 +++ 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseFinderCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseFinderCommand.cs index ac94ec06303..39bcc3cc158 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseFinderCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseFinderCommand.cs @@ -91,7 +91,7 @@ private string QueryAsJoinedString protected virtual PackageFieldMatchOption GetExactAsMatchOption() { return this.Exact.ToBool() - ? PackageFieldMatchOption.EqualsCaseInsensitive + ? PackageFieldMatchOption.Equals : PackageFieldMatchOption.ContainsCaseInsensitive; } diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseLifecycleCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseLifecycleCommand.cs index d5d4f3c3408..eef24d24ea1 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseLifecycleCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/BaseLifecycleCommand.cs @@ -9,8 +9,6 @@ namespace Microsoft.WinGet.Client.Commands using System; using System.IO; using System.Management.Automation; - using System.Reflection; - using System.Resources; using Microsoft.Management.Deployment; using Microsoft.WinGet.Client.Errors; using Microsoft.WinGet.Client.Helpers; @@ -57,6 +55,14 @@ public string Log } } + /// + protected override PackageFieldMatchOption GetExactAsMatchOption() + { + return this.Exact.ToBool() + ? PackageFieldMatchOption.Equals + : PackageFieldMatchOption.EqualsCaseInsensitive; + } + /// /// Executes a command targeting a specific package version. /// @@ -83,7 +89,7 @@ private CatalogPackage GetCatalogPackage(CompositeSearchBehavior behavior) } else { - var results = this.FindPackages(behavior, 2); + var results = this.FindPackages(behavior, 0); if (results.Count == 1) { return results[0].CatalogPackage; @@ -107,18 +113,13 @@ private PackageVersionId GetPackageVersionId(CatalogPackage package) for (var i = 0; i < versions.Count; i++) { - // PackageVersionInfo.DisplayName (?) - bool match = this.Version.Equals( - versions[i].Version, - StringComparison.OrdinalIgnoreCase); - - if (match) + if (versions[i].Version.CompareTo(this.Version) == 0) { return versions[i]; } } - throw new ArgumentException("No version found matching: " + this.Version); + throw new ArgumentException(Constants.ResourceManager.GetString("ExceptionMessages_VersionNotFound")); } else { diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs index 57142e8f51f..6aa731ab624 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs @@ -10,7 +10,6 @@ namespace Microsoft.WinGet.Client.Commands { - using System; using System.Management.Automation; using Microsoft.Management.Deployment; using Microsoft.WinGet.Client.Helpers; diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs index 165341cf1b7..c6b195231cf 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs @@ -6,7 +6,6 @@ namespace Microsoft.WinGet.Client.Commands { - using System; using System.Management.Automation; using Microsoft.Management.Deployment; using Microsoft.WinGet.Client.Helpers; diff --git a/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.Designer.cs b/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.Designer.cs index b0b9eed49bf..4660212397f 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.Designer.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.Designer.cs @@ -113,5 +113,14 @@ internal static string ExceptionMessages_VagueSearch { return ResourceManager.GetString("ExceptionMessages_VagueSearch", resourceCulture); } } + + /// + /// Looks up a localized string similar to No version matched the given input criteria.. + /// + internal static string ExceptionMessages_VersionNotFound { + get { + return ResourceManager.GetString("ExceptionMessages_VersionNotFound", resourceCulture); + } + } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.resx b/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.resx index dfa3e748d20..bb24c59bd8a 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.resx +++ b/src/PowerShell/Microsoft.WinGet.Client/Resources/Resources.resx @@ -135,4 +135,7 @@ '{0}', '{1}', and {2} other package(s) matched the input criteria. Please refine the input. + + No version matched the given input criteria. + \ No newline at end of file