-
Notifications
You must be signed in to change notification settings - Fork 75
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
Conversation
…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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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
.
There was a problem hiding this comment.
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.
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:
|
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.Closes #189