mirror of https://github.com/docker/cli.git
Add bash completion for the `context` command family
Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
parent
48bd4c6deb
commit
41bd8dad8c
|
@ -178,6 +178,31 @@ __docker_complete_container_ids() {
|
|||
COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
|
||||
}
|
||||
|
||||
# __docker_contexts returns a list of contexts without the special "default" context.
|
||||
# Completions may be added with `--add`, e.g. `--add default`.
|
||||
__docker_contexts() {
|
||||
local add=()
|
||||
while true ; do
|
||||
case "$1" in
|
||||
--add)
|
||||
add+=("$2")
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
__docker_q context ls -q
|
||||
echo "${add[@]}"
|
||||
}
|
||||
|
||||
__docker_complete_contexts() {
|
||||
local contexts=( $(__docker_contexts "$@") )
|
||||
COMPREPLY=( $(compgen -W "${contexts[*]}" -- "$cur") )
|
||||
}
|
||||
|
||||
|
||||
# __docker_images returns a list of images. For each image, up to three representations
|
||||
# can be generated: the repository (e.g. busybox), repository:tag (e.g. busybox:latest)
|
||||
# and the ID (e.g. sha256:ee22cbbd4ea3dff63c86ba60c7691287c321e93adfc1009604eb1dde7ec88645).
|
||||
|
@ -2234,6 +2259,172 @@ _docker_container_wait() {
|
|||
}
|
||||
|
||||
|
||||
_docker_context() {
|
||||
local subcommands="
|
||||
create
|
||||
export
|
||||
import
|
||||
inspect
|
||||
ls
|
||||
rm
|
||||
update
|
||||
use
|
||||
"
|
||||
local aliases="
|
||||
list
|
||||
remove
|
||||
"
|
||||
__docker_subcommands "$subcommands $aliases" && return
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_create() {
|
||||
case "$prev" in
|
||||
--default-stack-orchestrator)
|
||||
COMPREPLY=( $( compgen -W "all kubernetes swarm" -- "$cur" ) )
|
||||
return
|
||||
;;
|
||||
--description|--docker|--kubernetes)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--default-stack-orchestrator --description --docker --help --kubernetes" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_export() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help --kubeconfig" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
local counter=$(__docker_pos_first_nonflag)
|
||||
if [ "$cword" -eq "$counter" ]; then
|
||||
__docker_complete_contexts
|
||||
elif [ "$cword" -eq "$((counter + 1))" ]; then
|
||||
_filedir
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_import() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
local counter=$(__docker_pos_first_nonflag)
|
||||
if [ "$cword" -eq "$counter" ]; then
|
||||
:
|
||||
elif [ "$cword" -eq "$((counter + 1))" ]; then
|
||||
_filedir
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_inspect() {
|
||||
case "$prev" in
|
||||
--format|-f)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker_complete_contexts
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_list() {
|
||||
_docker_context_ls
|
||||
}
|
||||
|
||||
_docker_context_ls() {
|
||||
case "$prev" in
|
||||
--format|-f)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--format -f --help --quiet -q" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_remove() {
|
||||
_docker_context_rm
|
||||
}
|
||||
|
||||
_docker_context_rm() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker_complete_contexts
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_update() {
|
||||
case "$prev" in
|
||||
--default-stack-orchestrator)
|
||||
COMPREPLY=( $( compgen -W "all kubernetes swarm" -- "$cur" ) )
|
||||
return
|
||||
;;
|
||||
--description|--docker|--kubernetes)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--default-stack-orchestrator --description --docker --help --kubernetes" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
local counter=$(__docker_pos_first_nonflag)
|
||||
if [ "$cword" -eq "$counter" ]; then
|
||||
__docker_complete_contexts
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_docker_context_use() {
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
local counter=$(__docker_pos_first_nonflag)
|
||||
if [ "$cword" -eq "$counter" ]; then
|
||||
__docker_complete_contexts --add default
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
_docker_commit() {
|
||||
_docker_container_commit
|
||||
}
|
||||
|
@ -5147,6 +5338,7 @@ _docker() {
|
|||
local management_commands=(
|
||||
config
|
||||
container
|
||||
context
|
||||
image
|
||||
network
|
||||
node
|
||||
|
|
Loading…
Reference in New Issue