Skip to content

Commit

Permalink
Add zsh completion for 'docker swarm' commands
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
  • Loading branch information
sdurrheimer committed Jul 3, 2016
1 parent 6aacb18 commit 2086663
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions contrib/completion/zsh/_docker
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,74 @@ __docker_node_subcommand() {

# EO node

# BO swarm

__docker_swarm_commands() {
local -a _docker_swarm_subcommands
_docker_swarm_subcommands=(
"init:Initialize a Swarm"
"inspect:Inspect the Swarm"
"join:Join a Swarm as a node and/or manager"
"leave:Leave a Swarm"
"update:Update the Swarm"
)
_describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands
}

__docker_swarm_subcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1

opts_help=("(: -)--help[Print usage]")

case "$words[1]" in
(init)
_arguments $(__docker_arguments) \
$opts_help \
"($help)--auto-accept=[Acceptance policy]:policy:(manager none worker)" \
"($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \
"($help)--force-new-cluster[Force create a new cluster from current state]" \
"($help)--listen-addr[Listen address]:ip\:port: " \
"($help)--secret[Set secret value needed to accept nodes into cluster]:secret: " && ret=0
;;
(inspect)
_arguments $(__docker_arguments) \
$opts_help \
"($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0
;;
(join)
_arguments $(__docker_arguments) \
$opts_help \
"($help)--ca-hash=[Hash of the Root Certificate Authority certificate used for trusted join]:hash: " \
"($help)--listen-addr[Listen address]:ip\:port: " \
"($help)--manager[Try joining as a manager]" \
"($help)--secret[Secret for node acceptance]:secret: " \
"($help -):host\:port: " && ret=0
;;
(leave)
_arguments $(__docker_arguments) \
$opts_help && ret=0
;;
(update)
_arguments $(__docker_arguments) \
$opts_help \
"($help)--auto-accept=[Acceptance policy]:policy:(manager none worker)" \
"($help)--cert-expiry=[Validity period for node certificates]:duration: " \
"($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \
"($help)--secret[Set secret value needed to accept nodes into cluster]:secret: " \
"($help)--task-history-limit[Task history retention limit]:limit: " && ret=0
;;
(help)
_arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
;;
esac

return ret
}

# EO swarm

__docker_volume_complete_ls_filters() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
Expand Down Expand Up @@ -1547,6 +1615,23 @@ __docker_subcommand() {
"($help)--no-stream[Disable streaming stats and only pull the first result]" \
"($help -)*:containers:__docker_runningcontainers" && ret=0
;;
(swarm)
local curcontext="$curcontext" state
_arguments $(__docker_arguments) \
$opts_help \
"($help -): :->command" \
"($help -)*:: :->option-or-argument" && ret=0

case $state in
(command)
__docker_swarm_commands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:docker-${words[-1]}:
__docker_swarm_subcommand && ret=0
;;
esac
;;
(tag)
_arguments $(__docker_arguments) \
$opts_help \
Expand Down

0 comments on commit 2086663

Please sign in to comment.