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:
Krzysztof Pawlik 2020-11-19 01:32:33 +01:00 committed by GitHub
parent 4e485219d7
commit d807510dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 0 deletions

View File

@ -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`
## `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
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/).

View File

@ -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

View File

@ -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

View File

@ -42,6 +42,7 @@ func main() {
cliApp.Name = "helmfile"
cliApp.Usage = ""
cliApp.Version = version.Version
cliApp.EnableBashCompletion = true
cliApp.Flags = []cli.Flag{
cli.StringFlag{
Name: "helm-binary, b",