vmware-archive / kubecfg

A tool for managing complex enterprise Kubernetes environments as code.
Apache License 2.0
728 stars 62 forks source link

Parse tla/extvar options as StringArray not StringSlice #281

Closed camh- closed 4 years ago

camh- commented 4 years ago

The command line flags for top-level args (TLAs) and external variables (extVars) were being parsed with the Cobra flag type of StringSlice. A StringSlice allows multiple arguments with one flag name by separating the values with a comma. This means a comma cannot be used in the values. Also, Cobra StringSlice parses the argument with encoding/csv which escapes double-quotes in the value.

For code arguments, we need the value to be passed unchanged. Cobra StringArray does this, but does not allow the form --var=1,2,3 to provide a list of [1, 2, 3].

Change all of the --ext and --tla argument processing to use StringArray instead of StringSlice. This will change the behaviour for parsing non-code argument, but it could be argued that using StringSlice in the non-code arguments is also wrong. --ext-str foo=bar,baz means set foo to bar and baz to the value from the environment. There is no way to set foo to "bar,baz".

So let's make all cases possible at the expense of slightly more verbosity in a few cases (--ext-str foo=bar --ext-str baz) and use StringArray everywhere. This is also in line with the jsonnet command line parsing.

Update the test cases to include a test for an extVar with a comma and double quotes.

Fixes: #280

mkmik commented 4 years ago

Thanks.