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
22.94k stars 1.42k forks source link

Add "--exclude" option to winget-cli #4650

Open Ashcora opened 1 month ago

Ashcora commented 1 month ago

Description of the new feature / enhancement

The --exclude option is designed to provide users with more control over their command line operations. This feature allows users to specify a list of IDs that should be excluded from the operation. This is particularly useful in scenarios where the user wants to apply an operation to a large set of items but needs to exclude a few specific ones.

For example, if a user is performing a bulk delete operation but wants to preserve certain items, they could use the --exclude ids option to specify the IDs of the items to be preserved. This saves the user from having to manually separate these items before performing the operation.

Proposed technical implementation details

The --exclude option could be implemented as a command line argument that accepts a list of IDs. These IDs would then be used to filter out the corresponding items from the operation. The key point is that the --exclude ids option provides a way for users to specify a list of IDs to be excluded from the operation, and this list is then used to filter out the corresponding items before the operation is performed.

denelon commented 1 month ago

Are you familiar with the "Pin" command? I'd like to understand the scenario where the feature suggested wouldn't be achieved by using pinning.

Ashcora commented 1 month ago

Verification, see below.

image

Translated it means:

PS C:\Users\tobia> winget pin add --id Discord.Discord Found Discord [Discord.Discord] A PIN already exists for the Discord package. PS C:\Users\tobia> winget pin add --id nomic.gpt4all Found GPT4All [nomic.gpt4all] PIN successfully added

denelon commented 1 month ago

By adding "--force" you are telling WinGet to "ignore" the pin.

Microsoft Learn pin Command

Ashcora commented 1 month ago

Is there a way to force pending installations while excluding specific packages I don’t want to be considered? Sometimes packages need to be updated using the ‘force’ command, but even the pinned ones should be excluded based on our current understanding

But in fact, your proposed adaption works to ignore the pinned ones.

image
denelon commented 1 month ago

You can run winget upgrade to see which packages have upgrades available, then you can pass the Id's for the ones you want upgraded to the upgrade command.

winget upgrade <package id 1> <package id 2>

florelis commented 1 month ago

I like the idea for upgrade --all. I used to use --exclude in Portage all the time back when I used Gentoo.

Scenarios where this would be useful but pinning would be awkward:

In these cases I could do winget upgrade --all --exclude SomeApp as a one time thing. I could do it with pinning, but since I just want it one time, I would have to add the pin and then remove it later.

signe commented 1 month ago

Another valid case for this is when there is a separate paid/free version. i.e. MobaXterm (Mobatek.MobaXterm)

winget upgrade --all --force will "upgrade" MobaXterm to the free version of the application even if the paid version is installed, because the free version is what's available in the winget repository.

By adding "--force" you are telling WinGet to "ignore" the pin.

This isn't present in the winget-cli help for either pin or upgrade ... Yes, it's present in the online documentation for pin, but it's not self-evident. Other similar systems (apt, etc.) don't override pins, so it feels counterintuitive.