mirror of https://github.com/docker/cli.git
Add bash completion for `docker config` command family
This adds bash completion for - https://github.com/docker/cli/pull/45 - https://github.com/moby/moby/pull/32336 Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
parent
dfdbdab651
commit
c40952b305
|
@ -20,6 +20,7 @@
|
|||
# For several commands, the amount of completions can be configured by
|
||||
# setting environment variables.
|
||||
#
|
||||
# DOCKER_COMPLETION_SHOW_CONFIG_IDS
|
||||
# DOCKER_COMPLETION_SHOW_CONTAINER_IDS
|
||||
# DOCKER_COMPLETION_SHOW_NETWORK_IDS
|
||||
# DOCKER_COMPLETION_SHOW_NODE_IDS
|
||||
|
@ -61,6 +62,42 @@ __docker_q() {
|
|||
docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
|
||||
}
|
||||
|
||||
# __docker_configs returns a list of configs. Additional options to
|
||||
# `docker config ls` may be specified in order to filter the list, e.g.
|
||||
# `__docker_configs --filter label=stage=production`.
|
||||
# By default, only names are returned.
|
||||
# Set DOCKER_COMPLETION_SHOW_CONFIG_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_configs() {
|
||||
local format
|
||||
if [ "$1" = "--id" ] ; then
|
||||
format='{{.ID}}'
|
||||
shift
|
||||
elif [ "$1" = "--name" ] ; then
|
||||
format='{{.Name}}'
|
||||
shift
|
||||
elif [ "$DOCKER_COMPLETION_SHOW_CONFIG_IDS" = yes ] ; then
|
||||
format='{{.ID}} {{.Name}}'
|
||||
else
|
||||
format='{{.Name}}'
|
||||
fi
|
||||
|
||||
__docker_q config ls --format "$format" "$@"
|
||||
}
|
||||
|
||||
# __docker_complete_configs applies completion of configs based on the current value
|
||||
# of `$cur` or the value of the optional first option `--cur`, if given.
|
||||
__docker_complete_configs() {
|
||||
local current="$cur"
|
||||
if [ "$1" = "--cur" ] ; then
|
||||
current="$2"
|
||||
shift 2
|
||||
fi
|
||||
COMPREPLY=( $(compgen -W "$(__docker_configs "$@")" -- "$current") )
|
||||
}
|
||||
|
||||
# __docker_containers returns a list of containers. Additional options to
|
||||
# `docker ps` may be specified in order to filter the list, e.g.
|
||||
# `__docker_containers --filter status=running`
|
||||
|
@ -1096,6 +1133,117 @@ _docker_checkpoint_rm() {
|
|||
}
|
||||
|
||||
|
||||
_docker_config() {
|
||||
local subcommands="
|
||||
create
|
||||
inspect
|
||||
ls
|
||||
rm
|
||||
"
|
||||
local aliases="
|
||||
list
|
||||
remove
|
||||
"
|
||||
__docker_subcommands "$subcommands $aliases" && return
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_config_create() {
|
||||
case "$prev" in
|
||||
--label|-l)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help --label -l" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
local counter=$(__docker_pos_first_nonflag '--label|-l')
|
||||
if [ $cword -eq $((counter + 1)) ]; then
|
||||
_filedir
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_config_inspect() {
|
||||
case "$prev" in
|
||||
--format|-f)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker_complete_configs
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_config_list() {
|
||||
_docker_config_ls
|
||||
}
|
||||
|
||||
_docker_config_ls() {
|
||||
local key=$(__docker_map_key_of_current_option '--filter|-f')
|
||||
case "$key" in
|
||||
id)
|
||||
__docker_complete_configs --cur "${cur##*=}" --id
|
||||
return
|
||||
;;
|
||||
name)
|
||||
__docker_complete_configs --cur "${cur##*=}" --name
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$prev" in
|
||||
--filter|-f)
|
||||
COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
|
||||
__docker_nospace
|
||||
return
|
||||
;;
|
||||
--format)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--format --filter -f --help --quiet -q" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_config_remove() {
|
||||
_docker_config_rm
|
||||
}
|
||||
|
||||
_docker_config_rm() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker_complete_configs
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker_container() {
|
||||
local subcommands="
|
||||
attach
|
||||
|
@ -3146,6 +3294,7 @@ _docker_service_update_and_create() {
|
|||
|
||||
if [ "$subcommand" = "create" ] ; then
|
||||
options_with_args="$options_with_args
|
||||
--config
|
||||
--constraint
|
||||
--container-label
|
||||
--dns
|
||||
|
@ -3162,6 +3311,10 @@ _docker_service_update_and_create() {
|
|||
"
|
||||
|
||||
case "$prev" in
|
||||
--config)
|
||||
__docker_complete_configs
|
||||
return
|
||||
;;
|
||||
--env-file)
|
||||
_filedir
|
||||
return
|
||||
|
@ -3196,6 +3349,8 @@ _docker_service_update_and_create() {
|
|||
if [ "$subcommand" = "update" ] ; then
|
||||
options_with_args="$options_with_args
|
||||
--args
|
||||
--config-add
|
||||
--config-rm
|
||||
--constraint-add
|
||||
--constraint-rm
|
||||
--container-label-add
|
||||
|
@ -3223,6 +3378,10 @@ _docker_service_update_and_create() {
|
|||
"
|
||||
|
||||
case "$prev" in
|
||||
--config-add|--config-rm)
|
||||
__docker_complete_configs
|
||||
return
|
||||
;;
|
||||
--group-add|--group-rm)
|
||||
COMPREPLY=( $(compgen -g -- "$cur") )
|
||||
return
|
||||
|
@ -4594,6 +4753,7 @@ _docker() {
|
|||
shopt -s extglob
|
||||
|
||||
local management_commands=(
|
||||
config
|
||||
container
|
||||
image
|
||||
network
|
||||
|
|
Loading…
Reference in New Issue