Merge pull request #32305 from albers/completion-secret-ls--format
Add bash completion for `secret ls --format`
This commit is contained in:
commit
93955bd215
1 changed files with 46 additions and 9 deletions
|
@ -328,20 +328,40 @@ __docker_complete_runtimes() {
|
|||
COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") )
|
||||
}
|
||||
|
||||
# __docker_secrets returns a list of all secrets.
|
||||
# By default, only names of secrets are returned.
|
||||
# Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs of secrets.
|
||||
# __docker_secrets returns a list of secrets. Additional options to
|
||||
# `docker secret ls` may be specified in order to filter the list, e.g.
|
||||
# `__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() {
|
||||
local fields='$2' # default: name only
|
||||
[ "${DOCKER_COMPLETION_SHOW_SECRET_IDS}" = yes ] && fields='$1,$2' # ID and name
|
||||
local format
|
||||
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
|
||||
# of `$cur`.
|
||||
# of `$cur` or the value of the optional first option `--cur`, if given.
|
||||
__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.
|
||||
|
@ -3854,7 +3874,24 @@ _docker_secret_list() {
|
|||
}
|
||||
|
||||
_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
|
||||
--filter|-f)
|
||||
COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
|
||||
__docker_nospace
|
||||
return
|
||||
;;
|
||||
--format)
|
||||
return
|
||||
;;
|
||||
|
@ -3862,7 +3899,7 @@ _docker_secret_ls() {
|
|||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--format --help --quiet -q" -- "$cur" ) )
|
||||
COMPREPLY=( $( compgen -W "--format --filter -f --help --quiet -q" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue