Improve some multi-value flags to accept comma-separated values (#300)

fix cobra issue

Signed-off-by: yxxhero <aiopsclub@163.com>

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2022-08-18 19:30:30 +08:00 committed by GitHub
parent 7972a8921c
commit 429e724104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 55 deletions

View File

@ -31,8 +31,8 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command {
} }
f := cmd.Flags() f := cmd.Flags()
f.StringSliceVar(&applyImpl.ApplyOptions.Set, "set", nil, "additional values to be merged into the command") f.StringArrayVar(&applyImpl.ApplyOptions.Set, "set", nil, "additional values to be merged into the command")
f.StringSliceVar(&applyImpl.ApplyOptions.Values, "values", nil, "additional value files to be merged into the command") f.StringArrayVar(&applyImpl.ApplyOptions.Values, "values", nil, "additional value files to be merged into the command")
f.IntVar(&applyImpl.ApplyOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited") f.IntVar(&applyImpl.ApplyOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited")
f.BoolVar(&applyImpl.ApplyOptions.Validate, "validate", false, "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requires access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions") f.BoolVar(&applyImpl.ApplyOptions.Validate, "validate", false, "validate your manifests against the Kubernetes cluster you are currently pointing at. Note that this requires access to a Kubernetes cluster to obtain information necessary for validating, like the list of available API versions")
f.IntVar(&applyImpl.ApplyOptions.Context, "context", 0, "output NUM lines of context around changes") f.IntVar(&applyImpl.ApplyOptions.Context, "context", 0, "output NUM lines of context around changes")

View File

@ -106,16 +106,16 @@ func setGlobalOptionsForRootCmd(fs *pflag.FlagSet, globalOptions *config.GlobalO
fs.StringVarP(&globalOptions.HelmBinary, "helm-binary", "b", app.DefaultHelmBinary, "Path to the helm binary") fs.StringVarP(&globalOptions.HelmBinary, "helm-binary", "b", app.DefaultHelmBinary, "Path to the helm binary")
fs.StringVarP(&globalOptions.File, "file", "f", "", "load config from file or directory. defaults to `helmfile.yaml` or `helmfile.d`(means `helmfile.d/*.yaml`) in this preference") fs.StringVarP(&globalOptions.File, "file", "f", "", "load config from file or directory. defaults to `helmfile.yaml` or `helmfile.d`(means `helmfile.d/*.yaml`) in this preference")
fs.StringVarP(&globalOptions.Environment, "environment", "e", "", `specify the environment name. defaults to "default"`) fs.StringVarP(&globalOptions.Environment, "environment", "e", "", `specify the environment name. defaults to "default"`)
fs.StringArrayVarP(&globalOptions.StateValuesSet, "state-values-set", "s", nil, "set state values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)") fs.StringArrayVar(&globalOptions.StateValuesSet, "state-values-set", nil, "set state values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
fs.StringArrayVarP(&globalOptions.StateValuesFile, "state-values-file", "", nil, "specify state values in a YAML file") fs.StringArrayVar(&globalOptions.StateValuesFile, "state-values-file", nil, "specify state values in a YAML file")
fs.BoolVarP(&globalOptions.Quiet, "quiet", "q", false, "Silence output. Equivalent to log-level warn") fs.BoolVarP(&globalOptions.Quiet, "quiet", "q", false, "Silence output. Equivalent to log-level warn")
fs.StringVar(&globalOptions.KubeContext, "kube-context", "", "Set kubectl context. Uses current context by default") fs.StringVar(&globalOptions.KubeContext, "kube-context", "", "Set kubectl context. Uses current context by default")
fs.BoolVar(&globalOptions.Debug, "debug", false, "Enable verbose output for Helm and set log-level to debug, this disables --quiet/-q effect") fs.BoolVar(&globalOptions.Debug, "debug", false, "Enable verbose output for Helm and set log-level to debug, this disables --quiet/-q effect")
fs.BoolVar(&globalOptions.Color, "color", false, "Output with color") fs.BoolVar(&globalOptions.Color, "color", false, "Output with color")
fs.BoolVar(&globalOptions.NoColor, "no-color", false, "Output without color") fs.BoolVar(&globalOptions.NoColor, "no-color", false, "Output without color")
fs.StringVar(&globalOptions.LogLevel, "log-level", "info", "Set log level, default info") fs.StringVar(&globalOptions.LogLevel, "log-level", "info", "Set log level, default info")
fs.StringVar(&globalOptions.Namespace, "namespace", "", "Set namespace. Uses the namespace set in the context by default, and is available in templates as {{ .Namespace }}") fs.StringVarP(&globalOptions.Namespace, "namespace", "n", "", "Set namespace. Uses the namespace set in the context by default, and is available in templates as {{ .Namespace }}")
fs.StringVar(&globalOptions.Chart, "chart", "", "Set chart. Uses the chart set in release by default, and is available in template as {{ .Chart }}") fs.StringVarP(&globalOptions.Chart, "chart", "c", "", "Set chart. Uses the chart set in release by default, and is available in template as {{ .Chart }}")
fs.StringArrayVarP(&globalOptions.Selector, "selector", "l", nil, `Only run using the releases that match labels. Labels can take the form of foo=bar or foo!=bar. fs.StringArrayVarP(&globalOptions.Selector, "selector", "l", nil, `Only run using the releases that match labels. Labels can take the form of foo=bar or foo!=bar.
A release must match all labels in a group in order to be used. Multiple groups can be specified at once. A release must match all labels in a group in order to be used. Multiple groups can be specified at once.
--selector tier=frontend,tier!=proxy --selector tier=backend. Will match all frontend, non-proxy releases AND all backend releases. --selector tier=frontend,tier!=proxy --selector tier=backend. Will match all frontend, non-proxy releases AND all backend releases.

View File

@ -32,6 +32,7 @@ func NewStatusCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.StringVar(&statusOptions.Args, "args", "", "pass args to helm exec") f.StringVar(&statusOptions.Args, "args", "", "pass args to helm exec")
f.IntVar(&statusOptions.Concurrency, "concurrency", 0, "maximum number of concurrent helm processes to run, 0 is unlimited")
return cmd return cmd
} }

View File

@ -486,58 +486,57 @@ Iterate on the `helmfile.yaml` by referencing:
## CLI Reference ## CLI Reference
``` ```
NAME: Declaratively deploy your Kubernetes manifests, Kustomize configs, and Charts as Helm releases in one shot
helmfile
USAGE: Usage:
helmfile [global options] command [command options] [arguments...] helmfile [command]
VERSION: Available Commands:
0.145.2 apply Apply all resources from state file only when there are changes
build Build all resources from state file only when there are changes
COMMANDS: cache Cache management
deps update charts based on their requirements
repos sync repositories from state file (helm repo add && helm repo update)
charts DEPRECATED: sync releases from state file (helm upgrade --install) charts DEPRECATED: sync releases from state file (helm upgrade --install)
diff diff releases from state file against env (helm diff) completion Generate the autocompletion script for the specified shell
template template releases from state file against env (helm template)
write-values write values files for releases. Similar to `helmfile template`, write values files instead of manifests.
lint lint charts from state file (helm lint)
fetch fetch charts from state file
sync sync all resources from state file (repos, releases and chart deps)
apply apply all resources from state file only when there are changes
status retrieve status of releases in state file
delete DEPRECATED: delete releases from state file (helm delete) delete DEPRECATED: delete releases from state file (helm delete)
destroy deletes and then purges releases deps Update charts based on their requirements
test test releases from state file (helm test) destroy Destroys and then purges releases
build output compiled helmfile state(s) as YAML diff Diff releases defined in state file
list list releases defined in state file fetch Fetch charts from state file
cache cache management help Help about any command
lint Lint charts from state file (helm lint)
list List releases defined in state file
repos Repos releases defined in state file
status Retrieve status of releases in state file
sync Sync releases defined in state file
template Template releases defined in state file
test Test charts from state file (helm test)
version Show the version for Helmfile. version Show the version for Helmfile.
help, h Shows a list of commands or help for one command write-values Write values files for releases. Similar to `helmfile template`, write values files instead of manifests.
GLOBAL OPTIONS: Flags:
--helm-binary value, -b value path to helm binary (default: "helm") --allow-no-matching-release Do not exit with an error code if the provided selector has no matching releases.
--file helmfile.yaml, -f helmfile.yaml load config from file or directory. defaults to helmfile.yaml or `helmfile.d`(means `helmfile.d/*.yaml`) in this preference -c, --chart string Set chart. Uses the chart set in release by default, and is available in template as {{ .Chart }}
--environment value, -e value specify the environment name. defaults to "default"
--state-values-set value set state values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--state-values-file value specify state values in a YAML file
--quiet, -q Silence output. Equivalent to log-level warn
--kube-context value Set kubectl context. Uses current context by default
--debug Enable verbose output for Helm and set log-level to debug, this disables --quiet/-q effect
--color Output with color --color Output with color
--debug Enable verbose output for Helm and set log-level to debug, this disables --quiet/-q effect
-e, --environment string specify the environment name. defaults to "default"
-f, --file helmfile.yaml load config from file or directory. defaults to helmfile.yaml or `helmfile.d`(means `helmfile.d/*.yaml`) in this preference
-b, --helm-binary string Path to the helm binary (default "helm")
-h, --help help for helmfile
-i, --interactive Request confirmation before attempting to modify clusters
--kube-context string Set kubectl context. Uses current context by default
--log-level string Set log level, default info (default "info")
-n, --namespace string Set namespace. Uses the namespace set in the context by default, and is available in templates as {{ .Namespace }}
--no-color Output without color --no-color Output without color
--log-level value Set log level, default info -q, --quiet Silence output. Equivalent to log-level warn
--namespace value, -n value Set namespace. Uses the namespace set in the context by default, and is available in templates as {{ .Namespace }} -l, --selector strings Only run using the releases that match labels. Labels can take the form of foo=bar or foo!=bar.
--chart value, -c value Set chart. Uses the chart set in release by default, and is available in template as {{ .Chart }}
--selector value, -l value Only run using the releases that match labels. Labels can take the form of foo=bar or foo!=bar.
A release must match all labels in a group in order to be used. Multiple groups can be specified at once. A release must match all labels in a group in order to be used. Multiple groups can be specified at once.
--selector tier=frontend,tier!=proxy --selector tier=backend. Will match all frontend, non-proxy releases AND all backend releases. --selector tier=frontend,tier!=proxy --selector tier=backend. Will match all frontend, non-proxy releases AND all backend releases.
The name of a release can be used as a label. --selector name=myrelease The name of a release can be used as a label. --selector name=myrelease
--allow-no-matching-release Do not exit with an error code if the provided selector has no matching releases. --state-values-file strings specify state values in a YAML file
--interactive, -i Request confirmation before attempting to modify clusters --state-values-set strings set state values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--help, -h show help -v, --version version for helmfile
--version, -v print the version
Use "helmfile [command] --help" for more information about a command.
``` ```
### sync ### sync
@ -1378,7 +1377,7 @@ If you want to enable all experimental features set the env var to `HELMFILE_EXP
## `bash` and `zsh` completion ## `bash` and `zsh` completion
Copy `autocomplete/helmfile_bash_autocomplete` or `autocomplete/helmfile_zsh_autocomplete` (depending on your shell of choice) to directory where you keep other shell completion scripts to make sure it is sourced. helmfile completion --help
## Examples ## Examples