Zuehlke / cookbook-windev

One cookbook with resources for setting up a Windows development environment
MIT License
7 stars 1 forks source link

Fix using options in choco packages #50

Closed Bueddl closed 1 year ago

Bueddl commented 1 year ago

This change is related to PR #49 and exists for the same reason. Since chef passes the parameters to choco as an array the options can no longer be a plain string. This becomes apparent when using options together with params or when using more than one option since the entire string of options is then passed as one option to choco.

For example when specifying options "--x86 --ia test" and params the exec args become:

["C:\ProgramData\chocolatey/bin/choco.exe", "install", "-y", "--x86 --ia test--parameters /Password:postgres", "postgresql12"]

instead of:

["C:\ProgramData\chocolatey/bin/choco.exe", "install", "-y", "--x86", "--ia", "test", "--parameters /Password:postgres", "postgresql12"]

Note that here are actually 2 issues that are caused by this:

  1. missing space between the last option and the params
  2. all options are passed as a single option

I suggest switching to an array for the options which works fine and fixes both issues. However existing cookbooks that use options would have to be changed to use arrays instead of strings for specifying options.

Bueddl commented 1 year ago

Just to highlight how this would be used, consider this example:

{
  "default_attributes": {
    "choco_packages": [
      {
        "name": "postgresql",
        "params": "/Password:postgres",
        "version": "10.18.2",
        "options": ["--x86", "--params-global"]
      }
    ],
   ...
}
damphyr commented 1 year ago

You are changing the existing way of configuring choco_packages in a backwards incompatible way. We shouldn't break existing configurations while fixing a bug. So the code should accept either a single string or an Array of strings as options and construct the commandline accordingly.

Bueddl commented 1 year ago

You are changing the existing way of configuring choco_packages in a backwards incompatible way. We shouldn't break existing configurations while fixing a bug. So the code should accept either a single string or an Array of strings as options and construct the commandline accordingly.

Yes I was worried about that too. I will add changes to make it backwards compatible.

Bueddl commented 1 year ago

@damphyr I added a tokenization step in case the options were provided as a string.