зеркало из https://github.com/microsoft/docker.git
Merge pull request #28381 from sdurrheimer/zsh-completion-secret-command
Add zsh completion for the new 'docker secret' command
This commit is contained in:
Коммит
7ee0c3c9f8
|
@ -1515,6 +1515,107 @@ __docker_plugin_subcommand() {
|
|||
|
||||
# EO plugin
|
||||
|
||||
# BO secret
|
||||
|
||||
__docker_secrets() {
|
||||
[[ $PREFIX = -* ]] && return 1
|
||||
integer ret=1
|
||||
local line s
|
||||
declare -a lines secrets
|
||||
|
||||
type=$1; shift
|
||||
|
||||
lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}})
|
||||
|
||||
# Parse header line to find columns
|
||||
local i=1 j=1 k header=${lines[1]}
|
||||
declare -A begin end
|
||||
while (( j < ${#header} - 1 )); do
|
||||
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
|
||||
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
|
||||
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
|
||||
begin[${header[$i,$((j-1))]}]=$i
|
||||
end[${header[$i,$((j-1))]}]=$k
|
||||
done
|
||||
end[${header[$i,$((j-1))]}]=-1
|
||||
lines=(${lines[2,-1]})
|
||||
|
||||
# ID
|
||||
if [[ $type = (ids|all) ]]; then
|
||||
for line in $lines; do
|
||||
s="${line[${begin[ID]},${end[ID]}]%% ##}"
|
||||
secrets=($secrets $s)
|
||||
done
|
||||
fi
|
||||
|
||||
# Names
|
||||
if [[ $type = (names|all) ]]; then
|
||||
for line in $lines; do
|
||||
s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
|
||||
secrets=($secrets $s)
|
||||
done
|
||||
fi
|
||||
|
||||
_describe -t secrets-list "secrets" secrets "$@" && ret=0
|
||||
return ret
|
||||
}
|
||||
|
||||
__docker_complete_secrets() {
|
||||
[[ $PREFIX = -* ]] && return 1
|
||||
__docker_secrets all "$@"
|
||||
}
|
||||
|
||||
__docker_secret_commands() {
|
||||
local -a _docker_secret_subcommands
|
||||
_docker_secret_subcommands=(
|
||||
"create:Create a secret using stdin as content"
|
||||
"inspect:Display detailed information on one or more secrets"
|
||||
"ls:List secrets"
|
||||
"rm:Remove one or more secrets"
|
||||
)
|
||||
_describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands
|
||||
}
|
||||
|
||||
__docker_secret_subcommand() {
|
||||
local -a _command_args opts_help
|
||||
local expl help="--help"
|
||||
integer ret=1
|
||||
|
||||
opts_help=("(: -)--help[Print usage]")
|
||||
|
||||
case "$words[1]" in
|
||||
(create)
|
||||
_arguments $(__docker_arguments) \
|
||||
$opts_help \
|
||||
"($help)*"{-l=,--label=}"[Secret labels]:label: " \
|
||||
"($help -):secret: " && ret=0
|
||||
;;
|
||||
(inspect)
|
||||
_arguments $(__docker_arguments) \
|
||||
$opts_help \
|
||||
"($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \
|
||||
"($help -)*:secret:__docker_complete_secrets" && ret=0
|
||||
;;
|
||||
(ls|list)
|
||||
_arguments $(__docker_arguments) \
|
||||
$opts_help \
|
||||
"($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0
|
||||
;;
|
||||
(rm|remove)
|
||||
_arguments $(__docker_arguments) \
|
||||
$opts_help \
|
||||
"($help -)*:secret:__docker_complete_secrets" && ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
# EO secret
|
||||
|
||||
# BO service
|
||||
|
||||
__docker_service_complete_ls_filters() {
|
||||
|
@ -2302,6 +2403,23 @@ __docker_subcommand() {
|
|||
;;
|
||||
esac
|
||||
;;
|
||||
(secret)
|
||||
local curcontext="$curcontext" state
|
||||
_arguments $(__docker_arguments) \
|
||||
$opts_help \
|
||||
"($help -): :->command" \
|
||||
"($help -)*:: :->option-or-argument" && ret=0
|
||||
|
||||
case $state in
|
||||
(command)
|
||||
__docker_secret_commands && ret=0
|
||||
;;
|
||||
(option-or-argument)
|
||||
curcontext=${curcontext%:*:*}:docker-${words[-1]}:
|
||||
__docker_secret_subcommand && ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
(service)
|
||||
local curcontext="$curcontext" state
|
||||
_arguments $(__docker_arguments) \
|
||||
|
|
Загрузка…
Ссылка в новой задаче