Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed "-l" arg from "choco list" for Chocolatey 2.0 compatibility #191

Merged
merged 2 commits into from
Aug 26, 2023
Merged

removed "-l" arg from "choco list" for Chocolatey 2.0 compatibility #191

merged 2 commits into from
Aug 26, 2023

Conversation

JamesDBartlett3
Copy link
Contributor

@JamesDBartlett3 JamesDBartlett3 commented Jun 13, 2023

Running choco list -l on Chocolatey 2.0.0 produces the following error:
Invalid argument -l. This argument has been removed from the list command and cannot be used.
Removing the -l argument resolves the error and winfetch works properly again.
image

Closes #189

…atibility

Running `choco list -l` on Chocolatey 2.0.0 produces the following error:
```Invalid argument -l. This argument has been removed from the list command and cannot be used.```
Removing the `-l` switch resolves the error and winfetch works properly again.
winfetch.ps1 Outdated
@@ -872,7 +872,7 @@ function info_pkgs {
}

if ("choco" -in $ShowPkgs -and (Get-Command -Name choco -ErrorAction Ignore)) {
$chocopkg = (& choco list -l)[-1].Split(' ')[0] - 1
$chocopkg = (& choco list)[-1].Split(' ')[0] - 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$chocopkg = (& choco list)[-1].Split(' ')[0] - 1
$chocopkg = if (([version] (& choco --version).Split('-')[0]) -ge [version] '2.0.0') {
(& choco list)[-1].Split(' ')[0] - 1
} else {
(& choco list --local-only)[-1].Split(' ')[0] - 1
}

The fix for supporting Chocolatey CLI v2.x is a little more involved than just dropping the -l option, as this code will still need to support v1.x. In the older versions, choco list without the -l searches remote sources, and so it is still needed when you're running the older choco version.

My suggested edit here checks the version of Chocolatey CLI and adjusts the command as required. In the hopes of increasing readibilty and maintainability, I also expanded out the option to the full --local-only.

Copy link
Contributor Author

@JamesDBartlett3 JamesDBartlett3 Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that makes sense. How about making it a bit more concise, like this?

$chocopkg = Invoke-Expression $(
  "(& choco list" + $(if([version](& choco --version).Split('-')[0]`
  -lt [version]'2.0.0'){" --local-only"}) + ")[-1].Split(' ')[0] - 1")

Edit: I have pushed a new commit with my changes.

@rashil2000
Copy link
Member

Hey, thanks so much for the fix!

I'm not a choco user, so I just want to confirm if this been tested on a combination of scenarios:

  • Powershell Desktop and Powershell Core
  • Chocolatey v1 and Chocolatey v2
  • Windows 10 and Windows 11

@pgroyal22
Copy link

I tested on Windows 11 with Powershell Desktop chocolatey v2
image

@simsine
Copy link

simsine commented Aug 20, 2023

Works fine for me with Windows 11, Powershell Core 7, Choco v2
image

@rashil2000 rashil2000 merged commit 43ccb7f into lptstr:master Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clist deprecated in chocolatey v2
5 participants