mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #22369 from llua/zsh-completion
shell completion (zsh): bug fix and more improvements
This commit is contained in:
commit
908885bc49
@ -1,46 +1,57 @@
|
||||
#compdef salt salt-call salt-cp
|
||||
# The use-cache style is checked in a few places to allow caching minions, modules,
|
||||
# or the directory salt is installed in.
|
||||
# you can cache those three with:
|
||||
# zstyle ':completion:*:salt(|-cp|-call):*' use-cache true
|
||||
# or selectively:
|
||||
# zstyle ':completion::complete:salt(|-cp|-call):minions:' use-cache true
|
||||
# zstyle ':completion::complete:salt(|-cp|-call):modules:' use-cache true
|
||||
# zstyle ':completion::complete:salt(|-cp|-call):salt_dir:' use-cache true
|
||||
|
||||
|
||||
local state line curcontext="$curcontext" salt_dir cachefn
|
||||
|
||||
_modules(){
|
||||
local _funcs cachefn
|
||||
local _funcs cachefn expl curcontext=${curcontext%:*}:modules
|
||||
|
||||
zstyle -s ":completion:$curcontext:" cache-policy cachefn
|
||||
if [[ -z $cachefn ]]; then
|
||||
zstyle ":completion:$curcontext:" cache-policy _salt_caching_policy
|
||||
zstyle ":completion:$curcontext:" cache-policy _salt_caching_policy
|
||||
fi
|
||||
|
||||
if _cache_invalid salt/modules || ! _retrieve_cache salt/modules; then
|
||||
_funcs=( ${(M)${(f)"$(salt-call --local -d 2>/dev/null)"}##[[:alpha:][:digit:]._]##} )
|
||||
_store_cache salt/modules _funcs
|
||||
_funcs=( ${(M)${(f)"$(command salt-call --local -d 2>/dev/null)"}##[[:alnum:]._]##} )
|
||||
_store_cache salt/modules _funcs
|
||||
fi
|
||||
|
||||
_multi_parts "$@" . _funcs
|
||||
_wanted modules expl modules _multi_parts "$@" . _funcs
|
||||
}
|
||||
|
||||
_minions(){
|
||||
local _peons cachefn
|
||||
local _peons cachefn expl curcontext=${curcontext%:*}:minions
|
||||
|
||||
zstyle -s ":completion:$curcontext:" cache-policy cachefn
|
||||
if [[ -z $cachefn ]]; then
|
||||
zstyle ":completion:$curcontext:" cache-policy _salt_caching_policy
|
||||
zstyle ":completion:$curcontext:" cache-policy _salt_caching_policy
|
||||
fi
|
||||
|
||||
if _cache_invalid salt/minions || ! _retrieve_cache salt/minions; then
|
||||
_peons=( ${${(f)"$(salt-key -l acc 2>/dev/null)"}[2,-1]} )
|
||||
_store_cache salt/minions _peons
|
||||
_peons=( ${(f)"$(command salt-key -l acc 2>/dev/null)"} )
|
||||
_peons[(I)Accepted[[:space:]]Keys:]=()
|
||||
_store_cache salt/minions _peons
|
||||
fi
|
||||
|
||||
compadd "$@" -a _peons
|
||||
_wanted minions expl minions compadd "$@" -a _peons
|
||||
}
|
||||
|
||||
(( $+functions[_salt_caching_policy] )) ||
|
||||
_salt_caching_policy() {
|
||||
local -a oldp
|
||||
oldp=( "$1"(Nm+7) )
|
||||
(( $#oldp ))
|
||||
local -a oldp
|
||||
oldp=( "$1"(Nm+7) )
|
||||
(( $#oldp ))
|
||||
}
|
||||
|
||||
local -a _{target,master,logging,minion}_options _{common,out}_opts
|
||||
_target_options=(
|
||||
'(-E --pcre)'{-E,--pcre}'[use pcre regular expressions]:pcre:'
|
||||
'(-L --list)'{-L,--list}'[take a comma or space delimited list of servers.]:list:'
|
||||
@ -71,14 +82,14 @@ _master_options=(
|
||||
'(-b --batch --batch-size)'{-b,--batch,--batch-size}'[Execute the salt job in batch mode, pass number or percentage to batch.]:Batch Size:'
|
||||
'(-a --auth --eauth --extrenal-auth)'{-a,--auth,--eauth,--external-auth}'[Specify an external authentication system to use.]:eauth:'
|
||||
'(-T --make-token)'{-T,--make-token}'[Generate and save an authentication token for re-use.]'
|
||||
"--return[Set an alternative return method.]:Returners:_path_files -W '$salt_dir/returners' -g '[^_]*.py(\:r)'"
|
||||
'(-d --doc --documentation)'{-d,--doc,--documentation}"[Return the documentation for the specified module]:Module:_path_files -W '$salt_dir/modules' -g '[^_]*.py(\:r)'"
|
||||
'--return[Set an alternative return method.]:Returners:_path_files -W "$salt_dir/returners" -g "[^_]*.py(\:r)"'
|
||||
'(-d --doc --documentation)'{-d,--doc,--documentation}'[Return the documentation for the specified module]:Module:_path_files -W "$salt_dir/modules" -g "[^_]*.py(\:r)"'
|
||||
'--args-separator[Set the special argument used as a delimiter between command arguments of compound commands.]:Arg separator:'
|
||||
)
|
||||
|
||||
_minion_options=(
|
||||
"--return[Set an alternative return method.]:Returners:_path_files -W '$salt_dir/returners' -g '[^_]*.py(\:r)'"
|
||||
'(-d --doc --documentation)'{-d,--doc,--documentation}"[Return the documentation for the specified module]:Module:_path_files -W '$salt_dir/modules' -g '[^_]*.py(\:r)'"
|
||||
'--return[Set an alternative return method.]:Returners:_path_files -W "$salt_dir"/returners" -g "[^_]*.py(\:r)"'
|
||||
'(-d --doc --documentation)'{-d,--doc,--documentation}'[Return the documentation for the specified module]:Module:_path_files -W "$salt_dir/modules" -g "[^_]*.py(\:r)"'
|
||||
'(-g --grains)'{-g,--grains}'[Return the information generated by the salt grains]'
|
||||
{*-m,*--module-dirs}'[Specify an additional directory to pull modules from.]:Module Dirs:_files -/'
|
||||
'--master[Specify the master to use.]:Master:'
|
||||
@ -98,7 +109,7 @@ _logging_options=(
|
||||
)
|
||||
|
||||
_out_opts=(
|
||||
'(--out --output)'{--out,--output}"[Print the output using the specified outputter.]:Outputters:_path_files -W '$salt_dir/output' -g '[^_]*.py(\:r)'"
|
||||
'(--out --output)'{--out,--output}'[Print the output using the specified outputter.]:Outputters:_path_files -W "$salt_dir/output" -g "[^_]*.py(\:r)"'
|
||||
'(--out-indent --output-indent)'{--out-indent,--output-indent}'[Print the output indented by the provided value in spaces.]:Number:'
|
||||
'(--out-file --output-file)'{--out-file,--output-file}'[Write the output to the specified file]:Output File:_files'
|
||||
'(--no-color --no-colour)'{--no-color,--no-colour}'[Disable all colored output]'
|
||||
@ -109,7 +120,7 @@ _salt_comp(){
|
||||
case "$service" in
|
||||
salt)
|
||||
_arguments -C \
|
||||
"${words[(r)(-G|--grain)]+!}:minions:_minions" \
|
||||
"${words[(r)(-[GN]|--grain(|-regex))]+!}:minions:_minions" \
|
||||
':modules:_modules' \
|
||||
"$_target_options[@]" \
|
||||
"$_common_opts[@]" \
|
||||
@ -127,7 +138,7 @@ _salt_comp(){
|
||||
;;
|
||||
salt-cp)
|
||||
_arguments -C \
|
||||
"${words[(r)(-G|--grain)]+!}:minions:_minions" \
|
||||
"${words[(r)(-[GN]|--grain(|-regex))]+!}:minions:_minions" \
|
||||
"$_target_options[@]" \
|
||||
"$_common_opts[@]" \
|
||||
"$_logging_options[@]" \
|
||||
@ -137,14 +148,17 @@ _salt_comp(){
|
||||
esac
|
||||
}
|
||||
|
||||
zstyle -s ":completion:$curcontext:" cache-policy cachefn
|
||||
if [[ -z $cachefn ]]; then
|
||||
zstyle ":completion:$curcontext:" cache-policy _salt_caching_policy
|
||||
fi
|
||||
() {
|
||||
local curcontext=${curcontext%:*}:salt_dir
|
||||
zstyle -s ":completion:$curcontext:" cache-policy cachefn
|
||||
if [[ -z $cachefn ]]; then
|
||||
zstyle ":completion:${curcontext%:*}:salt_dir:" cache-policy _salt_caching_policy
|
||||
fi
|
||||
|
||||
if _cache_invalid salt/salt_dir || ! _retrieve_cache salt/salt_dir; then
|
||||
salt_dir="${$(python2 -c 'import salt; print(salt.__file__);')%__init__*}"
|
||||
_store_cache salt/salt_dir salt_dir
|
||||
fi
|
||||
if _cache_invalid salt/salt_dir || ! _retrieve_cache salt/salt_dir; then
|
||||
salt_dir="${$(python2 -c 'import salt; print(salt.__file__);')%__init__*}"
|
||||
_store_cache salt/salt_dir salt_dir
|
||||
fi
|
||||
}
|
||||
|
||||
_salt_comp "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user