microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.18k stars 1.45k forks source link

Improve matching logic with multiple sources #1663

Open denelon opened 2 years ago

denelon commented 2 years ago

Description of the new feature / enhancement

When one or more results are returned from all configured sources apply additional logic to help improve client behavior.

Specifically, when a user runs winget install <query> and the value in is either the PackageIdentifier, PackageName or Moniker for only one package, that package should be installed.

If more than one package matches in any of the three fields, the user must still disambiguate which result they want installed.

This would impact "install", "show", "upgrade", and "uninstall".

Proposed technical implementation details

No response

denelon commented 2 years ago

Precedence on "Id", "Name", and "Moniker" was selected due to the results of a search query where the "Id" and "Name" are always displayed. The Windows Terminal supports copy/paste shortcuts so those two fields were selected. As the "Id" doesn't contain any spaces, it negates the need to quote the value for command-line operations.

The priority would be "Id" as it is unique to a source, and does not contain spaces. Then the "Name" as it is displayed in search results. Finally, the "Moniker" is often a commonly known term, so if no other package has the requested value for "Id" or "Name", moniker is considered unique enough to disambiguate a requested package.

Note, the flow for matching a package against manifests is used in "Show", "Search", "Install", "Upgrade", and "Uninstall". Of these, "search" is the most permissive looking for substring matches (by default with no options configured) across multiple fields. The other commands use a more refined logic to attempt to find a single best match result to display or act on.

denelon commented 2 years ago

Related to

Trenly commented 1 year ago

[Policy] Area-Matching