Enable shell completion (#1559)
* feat: enable EnableBashCompletion to get --generate-bash-completion command line flag * feat: add scripts for bash and zsh * feat: document shell completion
This commit is contained in:
parent
4e485219d7
commit
d807510dd7
|
|
@ -1192,6 +1192,10 @@ Those features are set using the environment variable `HELMFILE_EXPERIMENTAL`. H
|
||||||
|
|
||||||
If you want to enable all experimental features set the env var to `HELMFILE_EXPERIMENTAL=true`
|
If you want to enable all experimental features set the env var to `HELMFILE_EXPERIMENTAL=true`
|
||||||
|
|
||||||
|
## `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.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
For more examples, see the [examples/README.md](https://github.com/roboll/helmfile/blob/master/examples/README.md) or the [`helmfile`](https://github.com/cloudposse/helmfiles/tree/master/releases) distribution by [Cloud Posse](https://github.com/cloudposse/).
|
For more examples, see the [examples/README.md](https://github.com/roboll/helmfile/blob/master/examples/README.md) or the [`helmfile`](https://github.com/cloudposse/helmfiles/tree/master/releases) distribution by [Cloud Posse](https://github.com/cloudposse/).
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
_helmfile_bash_autocomplete() {
|
||||||
|
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
|
||||||
|
local cur opts base
|
||||||
|
COMPREPLY=()
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
if [[ "$cur" == "-"* ]]; then
|
||||||
|
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
|
||||||
|
else
|
||||||
|
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
|
||||||
|
fi
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -o bashdefault -o default -o nospace -F _helmfile_bash_autocomplete helmfile
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
#compdef helmfile
|
||||||
|
|
||||||
|
_helmfile_zsh_autocomplete() {
|
||||||
|
|
||||||
|
local -a opts
|
||||||
|
local cur
|
||||||
|
cur=${words[-1]}
|
||||||
|
if [[ "$cur" == "-"* ]]; then
|
||||||
|
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
|
||||||
|
else
|
||||||
|
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${opts[1]}" != "" ]]; then
|
||||||
|
_describe 'values' opts
|
||||||
|
else
|
||||||
|
_files
|
||||||
|
fi
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
compdef _helmfile_zsh_autocomplete helmfile
|
||||||
1
main.go
1
main.go
|
|
@ -42,6 +42,7 @@ func main() {
|
||||||
cliApp.Name = "helmfile"
|
cliApp.Name = "helmfile"
|
||||||
cliApp.Usage = ""
|
cliApp.Usage = ""
|
||||||
cliApp.Version = version.Version
|
cliApp.Version = version.Version
|
||||||
|
cliApp.EnableBashCompletion = true
|
||||||
cliApp.Flags = []cli.Flag{
|
cliApp.Flags = []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "helm-binary, b",
|
Name: "helm-binary, b",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue