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.29k stars 1.45k forks source link

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

Open Ashcora opened 4 months ago

Ashcora commented 4 months 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 3 months 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 3 months 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 3 months ago

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

Microsoft Learn pin Command

Ashcora commented 3 months 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 3 months 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 3 months 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 3 months 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.

pbargiona commented 5 days ago

If the program is reporting its version wrongly pin can be awkward.

Example: Program A is reporting version 1.1.1, when it is actually 1.1.1.123456.

This makes every single winget upgrade --all to reinstall the patch 123456, since 1.1.1.123456 is bigger than flat 1.1.1.

Pinning 1.1.1 down would prevent a future 1.1.1.23456 patch to be installed through winget upgrade --all so it can be awkward to track.

Having an --exclude tag could make this easier, so that you could run something like winget upgrade --all --exclude --id Awkward.App --version 1.1.1.123456 wich would not reinstall it every single time, but also allow for the novel 234567 patch to be installed as soon as it is released. If the problem then persists, instead of needing a new pin, you only have to change the --version tag from your upgrade command.

sharunkumar commented 7 hours 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.

I tried by adding a pin using winget pin add but now winget upgrade --all does not upgrade the packages that are not pinned:

Image

Image

pbargiona commented 4 hours ago

I'm a PhD in law. Exclude is a perspective. Pin is usable. We think of this differently. The exclude I think of is a pinned malfunctioning 'winget upgrade --all' due to malicious version reporting from driver easy. God might be mighty against them.