-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support package parameters and install arguments starting with dashes #29
Support package parameters and install arguments starting with dashes #29
Conversation
…tall-Package This sidesteps all issues caused by having a list of parameters embedded inside another list of parameters. In particular, it provides support for package parameters/install arguments which start with dashes (such as used by the visualstudio2019buildtools [1] package). If the user sets PackageParameters/InstallArguments and at the same time provides values for them in AdditionalArguments (the existing way), the values from AdditionalArguments take precedence. [1] https://community.chocolatey.org/packages/visualstudio2019buildtools
If you are OK with the design, I can add some tests. |
Chocolatey packages are supposed to use slashes, not dashes, for package parameters. That's the standard that Chocolatey's Get-PackageParameters cmdlet uses. See https://docs.chocolatey.org/en-us/create/functions/get-packageparameters#parameters-string and https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Get-PackageParameters.ps1#L65-L66 for more information If the package in question is passing anything and everything to the underlying installer, they really should be chocolatey arguments, not parameters, which are not supported with the free version of Chocolatey. See https://stackoverflow.com/a/37817046/14384982 See https://github.com/chocolatey-community/chocolatey-coreteampackages/blob/master/automatic/sysinternals/tools/chocolateyInstall.ps1#L4 for an example of how Chocolatey package parameters should be handled within the package, which this Visual Studio package is not adhering to. |
This is just a convention introduced several years after the concept of package parameters first appeared in Chocolatey in 2013. Initially, there had been no facility for parsing the parameters and for 4 years packages had to invent their own parameter style and develop parsing code for it. Eventually, one convention became popular, at first as part of a community extension, and finally made its way into Chocolatey proper in 2017. But still, it was only a suggestion/recommendation, never a hard requirement. The fact is that there are many packages on chocolatey.org which do not use slashes for parameters and those packages were accepted by moderators without any issues. Some use dashes (examples: visualstudio2015*, visualstudio2017*, visualstudio2019* - over 80 packages in total), others yet another syntax (example: dotnetcore-*).
The possibility to pass additional arguments to the underlying installer is very much a feature of the free version of Chocolatey and predates even the concept of package parameters. Here there can be absolutely no control over the format of the arguments, because it depends entirely on the underlying installer. One could, for example, make a Chocolatey package for installing something using WinGet and users of that package would need to pass dashed arguments in --install-arguments if they wanted to tweak the installation, because that is the argument syntax accepted by winget.
(https://docs.chocolatey.org/en-us/choco/commands/install#options-and-switches) |
Sorry for the delay. Thanks for the historical background, that's helpful, and the design looks good to me. Like you mentioned, just add test coverage and it should be good to go. |
Apologies for the silence, I've been on vacation, Thanks for the green light, I'll get to work on the tests. |
I added test cases for I started adding tests for the specific case which motivated this PR (jberezanski@8256861), but ultimately decided against it, for these reasons:
|
The history of this branch is rather complicated, with several merges. Would you like me to clean it up, by recreating my changes on top of the current master? |
Looks good to me, just made a few edits and removed the workaround for Foil behavior. Regarding the commit history, I'll just squash merge it. |
Thanks! |
Some Chocolatey packages use package parameters which begin with dashes. One example is the Visual Studio family of packages:
Also, some native installers may accept dashed parameters (again, the Visual Studio Installer is one example).
The existing design of ChocolateyGet assumes that package parameters and install arguments are passed inside the
AdditionalArguments
dynamic option. However, the parsing code in Install-Package is very simple - it just splits the AdditionalArguments string by dashes and makes no attempt at handling quoting. This falls apart when the package parameters or installer arguments contain tokens which start with a dash.Rather than attempt to crawl deeper into the rabbit hole of quoting and complex regexes, this PR fixes the issue by promoting package parameters and install arguments to first-class provider options.
Examples which now work correctly:
The existing syntax (-params/-args inside AdditionalArguments) is left intact for backward compatibility and takes precedence, if the user specifies parameters using both methods at once.