Skip to content

Commit 584c08e

Browse files
committed
Added zsh completion for docker context subcommands
Signed-off-by: Christopher Svensson <stoffus@stoffus.com>
1 parent 2291f61 commit 584c08e

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

contrib/completion/zsh/_docker

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,83 @@ __docker_volume_subcommand() {
25442544

25452545
# EO volume
25462546

2547+
# BO context
2548+
2549+
__docker_complete_contexts() {
2550+
[[ $PREFIX = -* ]] && return 1
2551+
integer ret=1
2552+
declare -a contexts
2553+
2554+
contexts=(${(f)${:-"$(_call_program commands docker $docker_options context ls -q)"$'\n'}})
2555+
2556+
_describe -t context-list "context" contexts && ret=0
2557+
return ret
2558+
}
2559+
2560+
__docker_context_commands() {
2561+
local -a _docker_context_subcommands
2562+
_docker_context_subcommands=(
2563+
"create:Create new context"
2564+
"inspect:Display detailed information on one or more contexts"
2565+
"list:List available contexts"
2566+
"rm:Remove one or more contexts"
2567+
"show:Print the current context"
2568+
"update:Update a context"
2569+
"use:Set the default context"
2570+
)
2571+
_describe -t docker-context-commands "docker context command" _docker_context_subcommands
2572+
}
2573+
2574+
__docker_context_subcommand() {
2575+
local -a _command_args opts_help
2576+
local expl help="--help"
2577+
integer ret=1
2578+
2579+
opts_help=("(: -)--help[Print usage]")
2580+
2581+
case "$words[1]" in
2582+
(create)
2583+
_arguments $(__docker_arguments) \
2584+
$opts_help \
2585+
"($help)--default-stack-orchestrator=[Default orchestrator for stack operations to use with this context]:default-stack-orchestrator:(swarm kubernetes all)" \
2586+
"($help)--description=[Description of the context]:description:" \
2587+
"($help)--docker=[Set the docker endpoint]:docker:" \
2588+
"($help)--kubernetes=[Set the kubernetes endpoint]:kubernetes:" \
2589+
"($help)--from=[Create context from a named context]:from:__docker_complete_contexts" \
2590+
"($help -):name: " && ret=0
2591+
;;
2592+
(use)
2593+
_arguments $(__docker_arguments) \
2594+
$opts_help \
2595+
"($help -)1:context:__docker_complete_contexts" && ret=0
2596+
;;
2597+
(inspect)
2598+
_arguments $(__docker_arguments) \
2599+
$opts_help \
2600+
"($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \
2601+
"($help -)1:context:__docker_complete_contexts" && ret=0
2602+
;;
2603+
(rm)
2604+
_arguments $(__docker_arguments) \
2605+
$opts_help \
2606+
"($help -)1:context:__docker_complete_contexts" && ret=0
2607+
;;
2608+
(update)
2609+
_arguments $(__docker_arguments) \
2610+
$opts_help \
2611+
"($help)--default-stack-orchestrator=[Default orchestrator for stack operations to use with this context]:default-stack-orchestrator:(swarm kubernetes all)" \
2612+
"($help)--description=[Description of the context]:description:" \
2613+
"($help)--docker=[Set the docker endpoint]:docker:" \
2614+
"($help)--kubernetes=[Set the kubernetes endpoint]:kubernetes:" \
2615+
"($help -):name:" && ret=0
2616+
;;
2617+
esac
2618+
2619+
return ret
2620+
}
2621+
2622+
# EO context
2623+
25472624
__docker_caching_policy() {
25482625
oldp=( "$1"(Nmh+1) ) # 1 hour
25492626
(( $#oldp ))
@@ -2631,6 +2708,23 @@ __docker_subcommand() {
26312708
;;
26322709
esac
26332710
;;
2711+
(context)
2712+
local curcontext="$curcontext" state
2713+
_arguments $(__docker_arguments) \
2714+
$opts_help \
2715+
"($help -): :->command" \
2716+
"($help -)*:: :->option-or-argument" && ret=0
2717+
2718+
case $state in
2719+
(command)
2720+
__docker_context_commands && ret=0
2721+
;;
2722+
(option-or-argument)
2723+
curcontext=${curcontext%:*:*}:docker-${words[-1]}:
2724+
__docker_context_subcommand && ret=0
2725+
;;
2726+
esac
2727+
;;
26342728
(daemon)
26352729
_arguments $(__docker_arguments) \
26362730
$opts_help \

0 commit comments

Comments
 (0)