mirror of https://github.com/docker/cli.git
Add bash completion for `secret ls --format`
Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
parent
5ef17bfc68
commit
10638a7a3e
|
@ -328,20 +328,40 @@ __docker_complete_runtimes() {
|
||||||
COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") )
|
COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") )
|
||||||
}
|
}
|
||||||
|
|
||||||
# __docker_secrets returns a list of all secrets.
|
# __docker_secrets returns a list of secrets. Additional options to
|
||||||
# By default, only names of secrets are returned.
|
# `docker secret ls` may be specified in order to filter the list, e.g.
|
||||||
# Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs of secrets.
|
# `__docker_secrets --filter label=stage=production`
|
||||||
|
# By default, only names are returned.
|
||||||
|
# Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs.
|
||||||
|
# An optional first option `--id|--name` may be used to limit the
|
||||||
|
# output to the IDs or names of matching items. This setting takes
|
||||||
|
# precedence over the environment setting.
|
||||||
__docker_secrets() {
|
__docker_secrets() {
|
||||||
local fields='$2' # default: name only
|
local format
|
||||||
[ "${DOCKER_COMPLETION_SHOW_SECRET_IDS}" = yes ] && fields='$1,$2' # ID and name
|
if [ "$1" = "--id" ] ; then
|
||||||
|
format='{{.ID}}'
|
||||||
|
shift
|
||||||
|
elif [ "$1" = "--name" ] ; then
|
||||||
|
format='{{.Name}}'
|
||||||
|
shift
|
||||||
|
elif [ "$DOCKER_COMPLETION_SHOW_SECRET_IDS" = yes ] ; then
|
||||||
|
format='{{.ID}} {{.Name}}'
|
||||||
|
else
|
||||||
|
format='{{.Name}}'
|
||||||
|
fi
|
||||||
|
|
||||||
__docker_q secret ls | awk "NR>1 {print $fields}"
|
__docker_q secret ls --format "$format" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# __docker_complete_secrets applies completion of secrets based on the current value
|
# __docker_complete_secrets applies completion of secrets based on the current value
|
||||||
# of `$cur`.
|
# of `$cur` or the value of the optional first option `--cur`, if given.
|
||||||
__docker_complete_secrets() {
|
__docker_complete_secrets() {
|
||||||
COMPREPLY=( $(compgen -W "$(__docker_secrets)" -- "$cur") )
|
local current="$cur"
|
||||||
|
if [ "$1" = "--cur" ] ; then
|
||||||
|
current="$2"
|
||||||
|
shift 2
|
||||||
|
fi
|
||||||
|
COMPREPLY=( $(compgen -W "$(__docker_secrets "$@")" -- "$current") )
|
||||||
}
|
}
|
||||||
|
|
||||||
# __docker_stacks returns a list of all stacks.
|
# __docker_stacks returns a list of all stacks.
|
||||||
|
@ -3854,7 +3874,24 @@ _docker_secret_list() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_docker_secret_ls() {
|
_docker_secret_ls() {
|
||||||
|
local key=$(__docker_map_key_of_current_option '--filter|-f')
|
||||||
|
case "$key" in
|
||||||
|
id)
|
||||||
|
__docker_complete_secrets --cur "${cur##*=}" --id
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
name)
|
||||||
|
__docker_complete_secrets --cur "${cur##*=}" --name
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
|
--filter|-f)
|
||||||
|
COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
|
||||||
|
__docker_nospace
|
||||||
|
return
|
||||||
|
;;
|
||||||
--format)
|
--format)
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
@ -3862,7 +3899,7 @@ _docker_secret_ls() {
|
||||||
|
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "--format --help --quiet -q" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--format --filter -f --help --quiet -q" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue