github.com/SamWhited/moby@v1.13.1/contrib/completion/zsh/_docker (about) 1 #compdef docker dockerd 2 # 3 # zsh completion for docker (http://docker.com) 4 # 5 # version: 0.3.0 6 # github: https://github.com/felixr/docker-zsh-completion 7 # 8 # contributors: 9 # - Felix Riedel 10 # - Steve Durrheimer 11 # - Vincent Bernat 12 # 13 # license: 14 # 15 # Copyright (c) 2013, Felix Riedel 16 # All rights reserved. 17 # 18 # Redistribution and use in source and binary forms, with or without 19 # modification, are permitted provided that the following conditions are met: 20 # * Redistributions of source code must retain the above copyright 21 # notice, this list of conditions and the following disclaimer. 22 # * Redistributions in binary form must reproduce the above copyright 23 # notice, this list of conditions and the following disclaimer in the 24 # documentation and/or other materials provided with the distribution. 25 # * Neither the name of the <organization> nor the 26 # names of its contributors may be used to endorse or promote products 27 # derived from this software without specific prior written permission. 28 # 29 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 30 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 31 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 33 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 35 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 38 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 # 40 41 # Short-option stacking can be enabled with: 42 # zstyle ':completion:*:*:docker:*' option-stacking yes 43 # zstyle ':completion:*:*:docker-*:*' option-stacking yes 44 __docker_arguments() { 45 if zstyle -t ":completion:${curcontext}:" option-stacking; then 46 print -- -s 47 fi 48 } 49 50 __docker_get_containers() { 51 [[ $PREFIX = -* ]] && return 1 52 integer ret=1 53 local kind type line s 54 declare -a running stopped lines args names 55 56 kind=$1; shift 57 type=$1; shift 58 [[ $kind = (stopped|all) ]] && args=($args -a) 59 60 lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) 61 62 # Parse header line to find columns 63 local i=1 j=1 k header=${lines[1]} 64 declare -A begin end 65 while (( j < ${#header} - 1 )); do 66 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 67 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 68 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 69 begin[${header[$i,$((j-1))]}]=$i 70 end[${header[$i,$((j-1))]}]=$k 71 done 72 end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line 73 lines=(${lines[2,-1]}) 74 75 # Container ID 76 if [[ $type = (ids|all) ]]; then 77 for line in $lines; do 78 s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" 79 s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" 80 s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" 81 if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then 82 stopped=($stopped $s) 83 else 84 running=($running $s) 85 fi 86 done 87 fi 88 89 # Names: we only display the one without slash. All other names 90 # are generated and may clutter the completion. However, with 91 # Swarm, all names may be prefixed by the swarm node name. 92 if [[ $type = (names|all) ]]; then 93 for line in $lines; do 94 names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) 95 # First step: find a common prefix and strip it (swarm node case) 96 (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} 97 # Second step: only keep the first name without a / 98 s=${${names:#*/*}[1]} 99 # If no name, well give up. 100 (( $#s != 0 )) || continue 101 s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" 102 s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" 103 if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then 104 stopped=($stopped $s) 105 else 106 running=($running $s) 107 fi 108 done 109 fi 110 111 [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 112 [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 113 return ret 114 } 115 116 __docker_complete_stopped_containers() { 117 [[ $PREFIX = -* ]] && return 1 118 __docker_get_containers stopped all "$@" 119 } 120 121 __docker_complete_running_containers() { 122 [[ $PREFIX = -* ]] && return 1 123 __docker_get_containers running all "$@" 124 } 125 126 __docker_complete_containers() { 127 [[ $PREFIX = -* ]] && return 1 128 __docker_get_containers all all "$@" 129 } 130 131 __docker_complete_containers_ids() { 132 [[ $PREFIX = -* ]] && return 1 133 __docker_get_containers all ids "$@" 134 } 135 136 __docker_complete_containers_names() { 137 [[ $PREFIX = -* ]] && return 1 138 __docker_get_containers all names "$@" 139 } 140 141 __docker_complete_info_plugins() { 142 [[ $PREFIX = -* ]] && return 1 143 integer ret=1 144 emulate -L zsh 145 setopt extendedglob 146 local -a plugins 147 plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) 148 _describe -t plugins "$1 plugins" plugins && ret=0 149 return ret 150 } 151 152 __docker_complete_images() { 153 [[ $PREFIX = -* ]] && return 1 154 integer ret=1 155 declare -a images 156 images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) 157 _describe -t docker-images "images" images && ret=0 158 __docker_complete_repositories_with_tags && ret=0 159 return ret 160 } 161 162 __docker_complete_repositories() { 163 [[ $PREFIX = -* ]] && return 1 164 integer ret=1 165 declare -a repos 166 repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) 167 repos=(${repos#<none>}) 168 _describe -t docker-repos "repositories" repos && ret=0 169 return ret 170 } 171 172 __docker_complete_repositories_with_tags() { 173 [[ $PREFIX = -* ]] && return 1 174 integer ret=1 175 declare -a repos onlyrepos matched 176 declare m 177 repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) 178 repos=(${${repos%:::<none>}#<none>}) 179 # Check if we have a prefix-match for the current prefix. 180 onlyrepos=(${repos%::*}) 181 for m in $onlyrepos; do 182 [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { 183 # Yes, complete with tags 184 repos=(${${repos/:::/:}/:/\\:}) 185 _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 186 return ret 187 } 188 done 189 # No, only complete repositories 190 onlyrepos=(${${repos%:::*}/:/\\:}) 191 _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 192 193 return ret 194 } 195 196 __docker_search() { 197 [[ $PREFIX = -* ]] && return 1 198 local cache_policy 199 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 200 if [[ -z "$cache_policy" ]]; then 201 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 202 fi 203 204 local searchterm cachename 205 searchterm="${words[$CURRENT]%/}" 206 cachename=_docker-search-$searchterm 207 208 local expl 209 local -a result 210 if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ 211 && ! _retrieve_cache ${cachename#_}; then 212 _message "Searching for ${searchterm}..." 213 result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) 214 _store_cache ${cachename#_} result 215 fi 216 _wanted dockersearch expl 'available images' compadd -a result 217 } 218 219 __docker_get_log_options() { 220 [[ $PREFIX = -* ]] && return 1 221 222 integer ret=1 223 local log_driver=${opt_args[--log-driver]:-"all"} 224 local -a awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options 225 226 awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream") 227 fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag") 228 gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels") 229 gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag") 230 journald_options=("env" "labels" "tag") 231 json_file_options=("env" "labels" "max-file" "max-size") 232 logentries_options=("logentries-token") 233 syslog_options=("env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") 234 splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") 235 236 [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 237 [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 238 [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 239 [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 240 [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 241 [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 242 [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 243 [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 244 [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 245 246 return ret 247 } 248 249 __docker_complete_log_drivers() { 250 [[ $PREFIX = -* ]] && return 1 251 integer ret=1 252 drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) 253 _describe -t log-drivers "log drivers" drivers && ret=0 254 return ret 255 } 256 257 __docker_complete_log_options() { 258 [[ $PREFIX = -* ]] && return 1 259 integer ret=1 260 261 if compset -P '*='; then 262 case "${${words[-1]%=*}#*=}" in 263 (syslog-format) 264 syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro') 265 _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0 266 ;; 267 *) 268 _message 'value' && ret=0 269 ;; 270 esac 271 else 272 __docker_get_log_options -qS "=" && ret=0 273 fi 274 275 return ret 276 } 277 278 __docker_complete_detach_keys() { 279 [[ $PREFIX = -* ]] && return 1 280 integer ret=1 281 282 compset -P "*," 283 keys=(${:-{a-z}}) 284 ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) 285 _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 286 _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 287 } 288 289 __docker_complete_pid() { 290 [[ $PREFIX = -* ]] && return 1 291 integer ret=1 292 local -a opts vopts 293 294 opts=('host') 295 vopts=('container') 296 297 if compset -P '*:'; then 298 case "${${words[-1]%:*}#*=}" in 299 (container) 300 __docker_complete_running_containers && ret=0 301 ;; 302 *) 303 _message 'value' && ret=0 304 ;; 305 esac 306 else 307 _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 308 _describe -t pid-opts "PID Options" opts && ret=0 309 fi 310 311 return ret 312 } 313 314 __docker_complete_runtimes() { 315 [[ $PREFIX = -* ]] && return 1 316 integer ret=1 317 318 emulate -L zsh 319 setopt extendedglob 320 local -a runtimes_opts 321 runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) 322 _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 323 } 324 325 __docker_complete_ps_filters() { 326 [[ $PREFIX = -* ]] && return 1 327 integer ret=1 328 329 if compset -P '*='; then 330 case "${${words[-1]%=*}#*=}" in 331 (ancestor) 332 __docker_complete_images && ret=0 333 ;; 334 (before|since) 335 __docker_complete_containers && ret=0 336 ;; 337 (health) 338 health_opts=('healthy' 'none' 'starting' 'unhealthy') 339 _describe -t health-filter-opts "health filter options" health_opts && ret=0 340 ;; 341 (id) 342 __docker_complete_containers_ids && ret=0 343 ;; 344 (is-task) 345 _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 346 ;; 347 (name) 348 __docker_complete_containers_names && ret=0 349 ;; 350 (network) 351 __docker_complete_networks && ret=0 352 ;; 353 (status) 354 status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') 355 _describe -t status-filter-opts "status filter options" status_opts && ret=0 356 ;; 357 (volume) 358 __docker_complete_volumes && ret=0 359 ;; 360 *) 361 _message 'value' && ret=0 362 ;; 363 esac 364 else 365 opts=('ancestor' 'before' 'exited' 'health' 'id' 'label' 'name' 'network' 'since' 'status' 'volume') 366 _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 367 fi 368 369 return ret 370 } 371 372 __docker_complete_search_filters() { 373 [[ $PREFIX = -* ]] && return 1 374 integer ret=1 375 declare -a boolean_opts opts 376 377 boolean_opts=('true' 'false') 378 opts=('is-automated' 'is-official' 'stars') 379 380 if compset -P '*='; then 381 case "${${words[-1]%=*}#*=}" in 382 (is-automated|is-official) 383 _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 384 ;; 385 *) 386 _message 'value' && ret=0 387 ;; 388 esac 389 else 390 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 391 fi 392 393 return ret 394 } 395 396 __docker_complete_images_filters() { 397 [[ $PREFIX = -* ]] && return 1 398 integer ret=1 399 declare -a boolean_opts opts 400 401 boolean_opts=('true' 'false') 402 opts=('before' 'dangling' 'label' 'reference' 'since') 403 404 if compset -P '*='; then 405 case "${${words[-1]%=*}#*=}" in 406 (before|reference|since) 407 __docker_complete_images && ret=0 408 ;; 409 (dangling) 410 _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 411 ;; 412 *) 413 _message 'value' && ret=0 414 ;; 415 esac 416 else 417 _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 418 fi 419 420 return ret 421 } 422 423 __docker_complete_events_filter() { 424 [[ $PREFIX = -* ]] && return 1 425 integer ret=1 426 declare -a opts 427 428 opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume') 429 430 if compset -P '*='; then 431 case "${${words[-1]%=*}#*=}" in 432 (container) 433 __docker_complete_containers && ret=0 434 ;; 435 (daemon) 436 emulate -L zsh 437 setopt extendedglob 438 local -a daemon_opts 439 daemon_opts=( 440 ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} 441 ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} 442 ) 443 _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 444 ;; 445 (event) 446 local -a event_opts 447 event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach' 448 'exec_start' 'export' 'health_status' 'import' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start' 449 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') 450 _describe -t event-filter-opts "event filter options" event_opts && ret=0 451 ;; 452 (image) 453 __docker_complete_images && ret=0 454 ;; 455 (network) 456 __docker_complete_networks && ret=0 457 ;; 458 (type) 459 local -a type_opts 460 type_opts=('container' 'daemon' 'image' 'network' 'volume') 461 _describe -t type-filter-opts "type filter options" type_opts && ret=0 462 ;; 463 (volume) 464 __docker_complete_volumes && ret=0 465 ;; 466 *) 467 _message 'value' && ret=0 468 ;; 469 esac 470 else 471 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 472 fi 473 474 return ret 475 } 476 477 __docker_complete_prune_filters() { 478 [[ $PREFIX = -* ]] && return 1 479 integer ret=1 480 declare -a opts 481 482 opts=('until') 483 484 if compset -P '*='; then 485 case "${${words[-1]%=*}#*=}" in 486 *) 487 _message 'value' && ret=0 488 ;; 489 esac 490 else 491 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 492 fi 493 494 return ret 495 } 496 497 # BO container 498 499 __docker_container_commands() { 500 local -a _docker_container_subcommands 501 _docker_container_subcommands=( 502 "attach:Attach to a running container" 503 "commit:Create a new image from a container's changes" 504 "cp:Copy files/folders between a container and the local filesystem" 505 "create:Create a new container" 506 "diff:Inspect changes on a container's filesystem" 507 "exec:Run a command in a running container" 508 "export:Export a container's filesystem as a tar archive" 509 "inspect:Display detailed information on one or more containers" 510 "kill:Kill one or more running containers" 511 "logs:Fetch the logs of a container" 512 "ls:List containers" 513 "pause:Pause all processes within one or more containers" 514 "port:List port mappings or a specific mapping for the container" 515 "prune:Remove all stopped containers" 516 "rename:Rename a container" 517 "restart:Restart one or more containers" 518 "rm:Remove one or more containers" 519 "run:Run a command in a new container" 520 "start:Start one or more stopped containers" 521 "stats:Display a live stream of container(s) resource usage statistics" 522 "stop:Stop one or more running containers" 523 "top:Display the running processes of a container" 524 "unpause:Unpause all processes within one or more containers" 525 "update:Update configuration of one or more containers" 526 "wait:Block until one or more containers stop, then print their exit codes" 527 ) 528 _describe -t docker-container-commands "docker container command" _docker_container_subcommands 529 } 530 531 __docker_container_subcommand() { 532 local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update 533 local expl help="--help" 534 integer ret=1 535 536 opts_attach_exec_run_start=( 537 "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" 538 ) 539 opts_create_run=( 540 "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" 541 "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " 542 "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " 543 "($help)*--cap-add=[Add Linux capabilities]:capability: " 544 "($help)*--cap-drop=[Drop Linux capabilities]:capability: " 545 "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " 546 "($help)--cidfile=[Write the container ID to the file]:CID file:_files" 547 "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " 548 "($help)*--device=[Add a host device to the container]:device:_files" 549 "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " 550 "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " 551 "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " 552 "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " 553 "($help)--disable-content-trust[Skip image verification]" 554 "($help)*--dns=[Custom DNS servers]:DNS server: " 555 "($help)*--dns-option=[Custom DNS options]:DNS option: " 556 "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " 557 "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " 558 "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " 559 "($help)*--env-file=[Read environment variables from a file]:environment file:_files" 560 "($help)*--expose=[Expose a port from the container without publishing it]: " 561 "($help)*--group=[Set one or more supplementary user groups for the container]:group:_groups" 562 "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" 563 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" 564 "($help)--init[Run an init inside the container that forwards signals and reaps processes]" 565 "($help)--ip=[Container IPv4 address]:IPv4: " 566 "($help)--ip6=[Container IPv6 address]:IPv6: " 567 "($help)--ipc=[IPC namespace to use]:IPC namespace: " 568 "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" 569 "($help)*--link=[Add link to another container]:link:->link" 570 "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " 571 "($help)*"{-l=,--label=}"[Container metadata]:label: " 572 "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" 573 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" 574 "($help)--mac-address=[Container MAC address]:MAC address: " 575 "($help)--name=[Container name]:name: " 576 "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" 577 "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " 578 "($help)--oom-kill-disable[Disable OOM Killer]" 579 "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" 580 "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" 581 "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" 582 "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" 583 "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" 584 "($help)--privileged[Give extended privileges to this container]" 585 "($help)--read-only[Mount the container's root filesystem as read only]" 586 "($help)*--security-opt=[Security options]:security option: " 587 "($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: " 588 "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " 589 "($help)*--sysctl=-[sysctl options]:sysctl: " 590 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" 591 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" 592 "($help)*--ulimit=[ulimit options]:ulimit: " 593 "($help)--userns=[Container user namespace]:user namespace:(host)" 594 "($help)--tmpfs[mount tmpfs]" 595 "($help)*-v[Bind mount a volume]:volume: " 596 "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" 597 "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " 598 "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" 599 ) 600 opts_create_run_update=( 601 "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" 602 "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" 603 "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " 604 "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " 605 "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " 606 "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " 607 "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " 608 "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " 609 "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " 610 "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " 611 "($help)--memory-reservation=[Memory soft limit]:Memory limit: " 612 "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " 613 "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" 614 ) 615 opts_help=("(: -)--help[Print usage]") 616 617 case "$words[1]" in 618 (attach) 619 _arguments $(__docker_arguments) \ 620 $opts_help \ 621 $opts_attach_exec_run_start \ 622 "($help)--no-stdin[Do not attach stdin]" \ 623 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 624 "($help -):containers:__docker_complete_running_containers" && ret=0 625 ;; 626 (commit) 627 _arguments $(__docker_arguments) \ 628 $opts_help \ 629 "($help -a --author)"{-a=,--author=}"[Author]:author: " \ 630 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 631 "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ 632 "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ 633 "($help -):container:__docker_complete_containers" \ 634 "($help -): :__docker_complete_repositories_with_tags" && ret=0 635 ;; 636 (cp) 637 local state 638 _arguments $(__docker_arguments) \ 639 $opts_help \ 640 "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ 641 "($help -)1:container:->container" \ 642 "($help -)2:hostpath:_files" && ret=0 643 case $state in 644 (container) 645 if compset -P "*:"; then 646 _files && ret=0 647 else 648 __docker_complete_containers -qS ":" && ret=0 649 fi 650 ;; 651 esac 652 ;; 653 (create) 654 local state 655 _arguments $(__docker_arguments) \ 656 $opts_help \ 657 $opts_create_run \ 658 $opts_create_run_update \ 659 "($help -): :__docker_complete_images" \ 660 "($help -):command: _command_names -e" \ 661 "($help -)*::arguments: _normal" && ret=0 662 case $state in 663 (link) 664 if compset -P "*:"; then 665 _wanted alias expl "Alias" compadd -E "" && ret=0 666 else 667 __docker_complete_running_containers -qS ":" && ret=0 668 fi 669 ;; 670 esac 671 ;; 672 (diff) 673 _arguments $(__docker_arguments) \ 674 $opts_help \ 675 "($help -)*:containers:__docker_complete_containers" && ret=0 676 ;; 677 (exec) 678 local state 679 _arguments $(__docker_arguments) \ 680 $opts_help \ 681 $opts_attach_exec_run_start \ 682 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 683 "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ 684 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ 685 "($help)--privileged[Give extended Linux capabilities to the command]" \ 686 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ 687 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ 688 "($help -):containers:__docker_complete_running_containers" \ 689 "($help -)*::command:->anycommand" && ret=0 690 case $state in 691 (anycommand) 692 shift 1 words 693 (( CURRENT-- )) 694 _normal && ret=0 695 ;; 696 esac 697 ;; 698 (export) 699 _arguments $(__docker_arguments) \ 700 $opts_help \ 701 "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ 702 "($help -)*:containers:__docker_complete_containers" && ret=0 703 ;; 704 (inspect) 705 _arguments $(__docker_arguments) \ 706 $opts_help \ 707 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 708 "($help -s --size)"{-s,--size}"[Display total file sizes]" \ 709 "($help -)*:containers:__docker_complete_containers" && ret=0 710 ;; 711 (kill) 712 _arguments $(__docker_arguments) \ 713 $opts_help \ 714 "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ 715 "($help -)*:containers:__docker_complete_running_containers" && ret=0 716 ;; 717 (logs) 718 _arguments $(__docker_arguments) \ 719 $opts_help \ 720 "($help)--details[Show extra details provided to logs]" \ 721 "($help -f --follow)"{-f,--follow}"[Follow log output]" \ 722 "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ 723 "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ 724 "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ 725 "($help -)*:containers:__docker_complete_containers" && ret=0 726 ;; 727 (ls|list) 728 _arguments $(__docker_arguments) \ 729 $opts_help \ 730 "($help -a --all)"{-a,--all}"[Show all containers]" \ 731 "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ 732 "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ 733 "($help)--format=[Pretty-print containers using a Go template]:template: " \ 734 "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ 735 "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ 736 "($help)--no-trunc[Do not truncate output]" \ 737 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 738 "($help -s --size)"{-s,--size}"[Display total file sizes]" \ 739 "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 740 ;; 741 (pause|unpause) 742 _arguments $(__docker_arguments) \ 743 $opts_help \ 744 "($help -)*:containers:__docker_complete_running_containers" && ret=0 745 ;; 746 (port) 747 _arguments $(__docker_arguments) \ 748 $opts_help \ 749 "($help -)1:containers:__docker_complete_running_containers" \ 750 "($help -)2:port:_ports" && ret=0 751 ;; 752 (prune) 753 _arguments $(__docker_arguments) \ 754 $opts_help \ 755 "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ 756 "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 757 ;; 758 (rename) 759 _arguments $(__docker_arguments) \ 760 $opts_help \ 761 "($help -):old name:__docker_complete_containers" \ 762 "($help -):new name: " && ret=0 763 ;; 764 (restart) 765 _arguments $(__docker_arguments) \ 766 $opts_help \ 767 "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ 768 "($help -)*:containers:__docker_complete_containers_ids" && ret=0 769 ;; 770 (rm) 771 local state 772 _arguments $(__docker_arguments) \ 773 $opts_help \ 774 "($help -f --force)"{-f,--force}"[Force removal]" \ 775 "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ 776 "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ 777 "($help -)*:containers:->values" && ret=0 778 case $state in 779 (values) 780 if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then 781 __docker_complete_containers && ret=0 782 else 783 __docker_complete_stopped_containers && ret=0 784 fi 785 ;; 786 esac 787 ;; 788 (run) 789 local state 790 _arguments $(__docker_arguments) \ 791 $opts_help \ 792 $opts_create_run \ 793 $opts_create_run_update \ 794 $opts_attach_exec_run_start \ 795 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 796 "($help)--health-cmd=[Command to run to check health]:command: " \ 797 "($help)--health-interval=[Time between running the check]:time: " \ 798 "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ 799 "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ 800 "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ 801 "($help)--rm[Remove intermediate containers when it exits]" \ 802 "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ 803 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 804 "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \ 805 "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ 806 "($help -): :__docker_complete_images" \ 807 "($help -):command: _command_names -e" \ 808 "($help -)*::arguments: _normal" && ret=0 809 case $state in 810 (link) 811 if compset -P "*:"; then 812 _wanted alias expl "Alias" compadd -E "" && ret=0 813 else 814 __docker_complete_running_containers -qS ":" && ret=0 815 fi 816 ;; 817 (storage-opt) 818 if compset -P "*="; then 819 _message "value" && ret=0 820 else 821 opts=('size') 822 _describe -t filter-opts "storage options" opts -qS "=" && ret=0 823 fi 824 ;; 825 esac 826 ;; 827 (start) 828 _arguments $(__docker_arguments) \ 829 $opts_help \ 830 $opts_attach_exec_run_start \ 831 "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ 832 "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \ 833 "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 834 ;; 835 (stats) 836 _arguments $(__docker_arguments) \ 837 $opts_help \ 838 "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ 839 "($help)--format=[Pretty-print images using a Go template]:template: " \ 840 "($help)--no-stream[Disable streaming stats and only pull the first result]" \ 841 "($help -)*:containers:__docker_complete_running_containers" && ret=0 842 ;; 843 (stop) 844 _arguments $(__docker_arguments) \ 845 $opts_help \ 846 "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ 847 "($help -)*:containers:__docker_complete_running_containers" && ret=0 848 ;; 849 (top) 850 local state 851 _arguments $(__docker_arguments) \ 852 $opts_help \ 853 "($help -)1:containers:__docker_complete_running_containers" \ 854 "($help -)*:: :->ps-arguments" && ret=0 855 case $state in 856 (ps-arguments) 857 _ps && ret=0 858 ;; 859 esac 860 ;; 861 (update) 862 local state 863 _arguments $(__docker_arguments) \ 864 $opts_help \ 865 opts_create_run_update \ 866 "($help -)*: :->values" && ret=0 867 case $state in 868 (values) 869 if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then 870 __docker_complete_stopped_containers && ret=0 871 else 872 __docker_complete_containers && ret=0 873 fi 874 ;; 875 esac 876 ;; 877 (wait) 878 _arguments $(__docker_arguments) \ 879 $opts_help \ 880 "($help -)*:containers:__docker_complete_running_containers" && ret=0 881 ;; 882 (help) 883 _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 884 ;; 885 esac 886 887 return ret 888 } 889 890 # EO container 891 892 # BO image 893 894 __docker_image_commands() { 895 local -a _docker_image_subcommands 896 _docker_image_subcommands=( 897 "build:Build an image from a Dockerfile" 898 "history:Show the history of an image" 899 "import:Import the contents from a tarball to create a filesystem image" 900 "inspect:Display detailed information on one or more images" 901 "load:Load an image from a tar archive or STDIN" 902 "ls:List images" 903 "prune:Remove unused images" 904 "pull:Pull an image or a repository from a registry" 905 "push:Push an image or a repository to a registry" 906 "rm:Remove one or more images" 907 "save:Save one or more images to a tar archive (streamed to STDOUT by default)" 908 "tag:Tag an image into a repository" 909 ) 910 _describe -t docker-image-commands "docker image command" _docker_image_subcommands 911 } 912 913 __docker_image_subcommand() { 914 local -a _command_args opts_help 915 local expl help="--help" 916 integer ret=1 917 918 opts_help=("(: -)--help[Print usage]") 919 920 case "$words[1]" in 921 (build) 922 _arguments $(__docker_arguments) \ 923 $opts_help \ 924 "($help)*--build-arg=[Build-time variables]:<varname>=<value>: " \ 925 "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ 926 "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ 927 "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ 928 "($help)--compress[Compress the build context using gzip]" \ 929 "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ 930 "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ 931 "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ 932 "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ 933 "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ 934 "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ 935 "($help)--disable-content-trust[Skip image verification]" \ 936 "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ 937 "($help)--force-rm[Always remove intermediate containers]" \ 938 "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ 939 "($help)*--label=[Set metadata for an image]:label=value: " \ 940 "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ 941 "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ 942 "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ 943 "($help)--no-cache[Do not use cache when building the image]" \ 944 "($help)--pull[Attempt to pull a newer version of the image]" \ 945 "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ 946 "($help)--rm[Remove intermediate containers after a successful build]" \ 947 "($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: " \ 948 "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ 949 "($help)*--ulimit=[ulimit options]:ulimit: " \ 950 "($help)--userns=[Container user namespace]:user namespace:(host)" \ 951 "($help -):path or URL:_directories" && ret=0 952 ;; 953 (history) 954 _arguments $(__docker_arguments) \ 955 $opts_help \ 956 "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ 957 "($help)--no-trunc[Do not truncate output]" \ 958 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 959 "($help -)*: :__docker_complete_images" && ret=0 960 ;; 961 (import) 962 _arguments $(__docker_arguments) \ 963 $opts_help \ 964 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 965 "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ 966 "($help -):URL:(- http:// file://)" \ 967 "($help -): :__docker_complete_repositories_with_tags" && ret=0 968 ;; 969 (inspect) 970 _arguments $(__docker_arguments) \ 971 $opts_help \ 972 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 973 "($help -)*:images:__docker_complete_images" && ret=0 974 ;; 975 (load) 976 _arguments $(__docker_arguments) \ 977 $opts_help \ 978 "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ 979 "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 980 ;; 981 (ls|list) 982 local state 983 _arguments $(__docker_arguments) \ 984 $opts_help \ 985 "($help -a --all)"{-a,--all}"[Show all images]" \ 986 "($help)--digests[Show digests]" \ 987 "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ 988 "($help)--format=[Pretty-print images using a Go template]:template: " \ 989 "($help)--no-trunc[Do not truncate output]" \ 990 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 991 "($help -): :__docker_complete_repositories" && ret=0 992 case $state in 993 (filter-options) 994 __docker_complete_images_filters && ret=0 995 ;; 996 esac 997 ;; 998 (prune) 999 _arguments $(__docker_arguments) \ 1000 $opts_help \ 1001 "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ 1002 "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ 1003 "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 1004 ;; 1005 (pull) 1006 _arguments $(__docker_arguments) \ 1007 $opts_help \ 1008 "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ 1009 "($help)--disable-content-trust[Skip image verification]" \ 1010 "($help -):name:__docker_search" && ret=0 1011 ;; 1012 (push) 1013 _arguments $(__docker_arguments) \ 1014 $opts_help \ 1015 "($help)--disable-content-trust[Skip image signing]" \ 1016 "($help -): :__docker_complete_images" && ret=0 1017 ;; 1018 (rm) 1019 _arguments $(__docker_arguments) \ 1020 $opts_help \ 1021 "($help -f --force)"{-f,--force}"[Force removal]" \ 1022 "($help)--no-prune[Do not delete untagged parents]" \ 1023 "($help -)*: :__docker_complete_images" && ret=0 1024 ;; 1025 (save) 1026 _arguments $(__docker_arguments) \ 1027 $opts_help \ 1028 "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ 1029 "($help -)*: :__docker_complete_images" && ret=0 1030 ;; 1031 (tag) 1032 _arguments $(__docker_arguments) \ 1033 $opts_help \ 1034 "($help -):source:__docker_complete_images"\ 1035 "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 1036 ;; 1037 (help) 1038 _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 1039 ;; 1040 esac 1041 1042 return ret 1043 } 1044 1045 # EO image 1046 1047 # BO network 1048 1049 __docker_network_complete_ls_filters() { 1050 [[ $PREFIX = -* ]] && return 1 1051 integer ret=1 1052 1053 if compset -P '*='; then 1054 case "${${words[-1]%=*}#*=}" in 1055 (driver) 1056 __docker_complete_info_plugins Network && ret=0 1057 ;; 1058 (id) 1059 __docker_complete_networks_ids && ret=0 1060 ;; 1061 (name) 1062 __docker_complete_networks_names && ret=0 1063 ;; 1064 (type) 1065 type_opts=('builtin' 'custom') 1066 _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0 1067 ;; 1068 *) 1069 _message 'value' && ret=0 1070 ;; 1071 esac 1072 else 1073 opts=('driver' 'id' 'label' 'name' 'type') 1074 _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 1075 fi 1076 1077 return ret 1078 } 1079 1080 __docker_get_networks() { 1081 [[ $PREFIX = -* ]] && return 1 1082 integer ret=1 1083 local line s 1084 declare -a lines networks 1085 1086 type=$1; shift 1087 1088 lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) 1089 1090 # Parse header line to find columns 1091 local i=1 j=1 k header=${lines[1]} 1092 declare -A begin end 1093 while (( j < ${#header} - 1 )); do 1094 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 1095 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 1096 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 1097 begin[${header[$i,$((j-1))]}]=$i 1098 end[${header[$i,$((j-1))]}]=$k 1099 done 1100 end[${header[$i,$((j-1))]}]=-1 1101 lines=(${lines[2,-1]}) 1102 1103 # Network ID 1104 if [[ $type = (ids|all) ]]; then 1105 for line in $lines; do 1106 s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" 1107 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 1108 s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" 1109 networks=($networks $s) 1110 done 1111 fi 1112 1113 # Names 1114 if [[ $type = (names|all) ]]; then 1115 for line in $lines; do 1116 s="${line[${begin[NAME]},${end[NAME]}]%% ##}" 1117 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 1118 s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" 1119 networks=($networks $s) 1120 done 1121 fi 1122 1123 _describe -t networks-list "networks" networks "$@" && ret=0 1124 return ret 1125 } 1126 1127 __docker_complete_networks() { 1128 [[ $PREFIX = -* ]] && return 1 1129 __docker_get_networks all "$@" 1130 } 1131 1132 __docker_complete_networks_ids() { 1133 [[ $PREFIX = -* ]] && return 1 1134 __docker_get_networks ids "$@" 1135 } 1136 1137 __docker_complete_networks_names() { 1138 [[ $PREFIX = -* ]] && return 1 1139 __docker_get_networks names "$@" 1140 } 1141 1142 __docker_network_commands() { 1143 local -a _docker_network_subcommands 1144 _docker_network_subcommands=( 1145 "connect:Connect a container to a network" 1146 "create:Creates a new network with a name specified by the user" 1147 "disconnect:Disconnects a container from a network" 1148 "inspect:Displays detailed information on a network" 1149 "ls:Lists all the networks created by the user" 1150 "prune:Remove all unused networks" 1151 "rm:Deletes one or more networks" 1152 ) 1153 _describe -t docker-network-commands "docker network command" _docker_network_subcommands 1154 } 1155 1156 __docker_network_subcommand() { 1157 local -a _command_args opts_help 1158 local expl help="--help" 1159 integer ret=1 1160 1161 opts_help=("(: -)--help[Print usage]") 1162 1163 case "$words[1]" in 1164 (connect) 1165 _arguments $(__docker_arguments) \ 1166 $opts_help \ 1167 "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ 1168 "($help)--ip=[Container IPv4 address]:IPv4: " \ 1169 "($help)--ip6=[Container IPv6 address]:IPv6: " \ 1170 "($help)*--link=[Add a link to another container]:link:->link" \ 1171 "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ 1172 "($help -)1:network:__docker_complete_networks" \ 1173 "($help -)2:containers:__docker_complete_containers" && ret=0 1174 1175 case $state in 1176 (link) 1177 if compset -P "*:"; then 1178 _wanted alias expl "Alias" compadd -E "" && ret=0 1179 else 1180 __docker_complete_running_containers -qS ":" && ret=0 1181 fi 1182 ;; 1183 esac 1184 ;; 1185 (create) 1186 _arguments $(__docker_arguments) -A '-*' \ 1187 $opts_help \ 1188 "($help)--attachable[Enable manual container attachment]" \ 1189 "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ 1190 "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ 1191 "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ 1192 "($help)--internal[Restricts external access to the network]" \ 1193 "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ 1194 "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ 1195 "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ 1196 "($help)--ipv6[Enable IPv6 networking]" \ 1197 "($help)*--label=[Set metadata on a network]:label=value: " \ 1198 "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ 1199 "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ 1200 "($help -)1:Network Name: " && ret=0 1201 ;; 1202 (disconnect) 1203 _arguments $(__docker_arguments) \ 1204 $opts_help \ 1205 "($help -)1:network:__docker_complete_networks" \ 1206 "($help -)2:containers:__docker_complete_containers" && ret=0 1207 ;; 1208 (inspect) 1209 _arguments $(__docker_arguments) \ 1210 $opts_help \ 1211 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 1212 "($help -)*:network:__docker_complete_networks" && ret=0 1213 ;; 1214 (ls) 1215 _arguments $(__docker_arguments) \ 1216 $opts_help \ 1217 "($help)--no-trunc[Do not truncate the output]" \ 1218 "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ 1219 "($help)--format=[Pretty-print networks using a Go template]:template: " \ 1220 "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0 1221 case $state in 1222 (filter-options) 1223 __docker_network_complete_ls_filters && ret=0 1224 ;; 1225 esac 1226 ;; 1227 (prune) 1228 _arguments $(__docker_arguments) \ 1229 $opts_help \ 1230 "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ 1231 "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 1232 ;; 1233 (rm) 1234 _arguments $(__docker_arguments) \ 1235 $opts_help \ 1236 "($help -)*:network:__docker_complete_networks" && ret=0 1237 ;; 1238 (help) 1239 _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 1240 ;; 1241 esac 1242 1243 return ret 1244 } 1245 1246 # EO network 1247 1248 # BO node 1249 1250 __docker_node_complete_ls_filters() { 1251 [[ $PREFIX = -* ]] && return 1 1252 integer ret=1 1253 1254 if compset -P '*='; then 1255 case "${${words[-1]%=*}#*=}" in 1256 (id) 1257 __docker_complete_nodes_ids && ret=0 1258 ;; 1259 (membership) 1260 membership_opts=('accepted' 'pending' 'rejected') 1261 _describe -t membership-opts "membership options" membership_opts && ret=0 1262 ;; 1263 (name) 1264 __docker_complete_nodes_names && ret=0 1265 ;; 1266 (role) 1267 role_opts=('manager' 'worker') 1268 _describe -t role-opts "role options" role_opts && ret=0 1269 ;; 1270 *) 1271 _message 'value' && ret=0 1272 ;; 1273 esac 1274 else 1275 opts=('id' 'label' 'membership' 'name' 'role') 1276 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 1277 fi 1278 1279 return ret 1280 } 1281 1282 __docker_node_complete_ps_filters() { 1283 [[ $PREFIX = -* ]] && return 1 1284 integer ret=1 1285 1286 if compset -P '*='; then 1287 case "${${words[-1]%=*}#*=}" in 1288 (desired-state) 1289 state_opts=('accepted' 'running') 1290 _describe -t state-opts "desired state options" state_opts && ret=0 1291 ;; 1292 *) 1293 _message 'value' && ret=0 1294 ;; 1295 esac 1296 else 1297 opts=('desired-state' 'id' 'label' 'name') 1298 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 1299 fi 1300 1301 return ret 1302 } 1303 1304 __docker_nodes() { 1305 [[ $PREFIX = -* ]] && return 1 1306 integer ret=1 1307 local line s 1308 declare -a lines nodes args 1309 1310 type=$1; shift 1311 filter=$1; shift 1312 [[ $filter != "none" ]] && args=("-f $filter") 1313 1314 lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) 1315 # Parse header line to find columns 1316 local i=1 j=1 k header=${lines[1]} 1317 declare -A begin end 1318 while (( j < ${#header} - 1 )); do 1319 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 1320 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 1321 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 1322 begin[${header[$i,$((j-1))]}]=$i 1323 end[${header[$i,$((j-1))]}]=$k 1324 done 1325 end[${header[$i,$((j-1))]}]=-1 1326 lines=(${lines[2,-1]}) 1327 1328 # Node ID 1329 if [[ $type = (ids|all) ]]; then 1330 for line in $lines; do 1331 s="${line[${begin[ID]},${end[ID]}]%% ##}" 1332 nodes=($nodes $s) 1333 done 1334 fi 1335 1336 # Names 1337 if [[ $type = (names|all) ]]; then 1338 for line in $lines; do 1339 s="${line[${begin[NAME]},${end[NAME]}]%% ##}" 1340 nodes=($nodes $s) 1341 done 1342 fi 1343 1344 _describe -t nodes-list "nodes" nodes "$@" && ret=0 1345 return ret 1346 } 1347 1348 __docker_complete_nodes() { 1349 [[ $PREFIX = -* ]] && return 1 1350 __docker_nodes all none "$@" 1351 } 1352 1353 __docker_complete_nodes_ids() { 1354 [[ $PREFIX = -* ]] && return 1 1355 __docker_nodes ids none "$@" 1356 } 1357 1358 __docker_complete_nodes_names() { 1359 [[ $PREFIX = -* ]] && return 1 1360 __docker_nodes names none "$@" 1361 } 1362 1363 __docker_complete_pending_nodes() { 1364 [[ $PREFIX = -* ]] && return 1 1365 __docker_nodes all "membership=pending" "$@" 1366 } 1367 1368 __docker_complete_manager_nodes() { 1369 [[ $PREFIX = -* ]] && return 1 1370 __docker_nodes all "role=manager" "$@" 1371 } 1372 1373 __docker_complete_worker_nodes() { 1374 [[ $PREFIX = -* ]] && return 1 1375 __docker_nodes all "role=worker" "$@" 1376 } 1377 1378 __docker_node_commands() { 1379 local -a _docker_node_subcommands 1380 _docker_node_subcommands=( 1381 "demote:Demote a node as manager in the swarm" 1382 "inspect:Display detailed information on one or more nodes" 1383 "ls:List nodes in the swarm" 1384 "promote:Promote a node as manager in the swarm" 1385 "rm:Remove one or more nodes from the swarm" 1386 "ps:List tasks running on one or more nodes, defaults to current node" 1387 "update:Update a node" 1388 ) 1389 _describe -t docker-node-commands "docker node command" _docker_node_subcommands 1390 } 1391 1392 __docker_node_subcommand() { 1393 local -a _command_args opts_help 1394 local expl help="--help" 1395 integer ret=1 1396 1397 opts_help=("(: -)--help[Print usage]") 1398 1399 case "$words[1]" in 1400 (rm|remove) 1401 _arguments $(__docker_arguments) \ 1402 $opts_help \ 1403 "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ 1404 "($help -)*:node:__docker_complete_pending_nodes" && ret=0 1405 ;; 1406 (demote) 1407 _arguments $(__docker_arguments) \ 1408 $opts_help \ 1409 "($help -)*:node:__docker_complete_manager_nodes" && ret=0 1410 ;; 1411 (inspect) 1412 _arguments $(__docker_arguments) \ 1413 $opts_help \ 1414 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 1415 "($help)--pretty[Print the information in a human friendly format]" \ 1416 "($help -)*:node:__docker_complete_nodes" && ret=0 1417 ;; 1418 (ls|list) 1419 _arguments $(__docker_arguments) \ 1420 $opts_help \ 1421 "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ 1422 "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 1423 case $state in 1424 (filter-options) 1425 __docker_node_complete_ls_filters && ret=0 1426 ;; 1427 esac 1428 ;; 1429 (promote) 1430 _arguments $(__docker_arguments) \ 1431 $opts_help \ 1432 "($help -)*:node:__docker_complete_worker_nodes" && ret=0 1433 ;; 1434 (ps) 1435 _arguments $(__docker_arguments) \ 1436 $opts_help \ 1437 "($help -a --all)"{-a,--all}"[Display all instances]" \ 1438 "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ 1439 "($help)--no-resolve[Do not map IDs to Names]" \ 1440 "($help)--no-trunc[Do not truncate output]" \ 1441 "($help -)*:node:__docker_complete_nodes" && ret=0 1442 case $state in 1443 (filter-options) 1444 __docker_node_complete_ps_filters && ret=0 1445 ;; 1446 esac 1447 ;; 1448 (update) 1449 _arguments $(__docker_arguments) \ 1450 $opts_help \ 1451 "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ 1452 "($help)*--label-add=[Add or update a node label]:key=value: " \ 1453 "($help)*--label-rm=[Remove a node label if exists]:label: " \ 1454 "($help)--role=[Role of the node]:role:(manager worker)" \ 1455 "($help -)1:node:__docker_complete_nodes" && ret=0 1456 ;; 1457 (help) 1458 _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 1459 ;; 1460 esac 1461 1462 return ret 1463 } 1464 1465 # EO node 1466 1467 # BO plugin 1468 1469 __docker_complete_plugins() { 1470 [[ $PREFIX = -* ]] && return 1 1471 integer ret=1 1472 local line s 1473 declare -a lines plugins 1474 1475 lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls)"$'\n'}}) 1476 1477 # Parse header line to find columns 1478 local i=1 j=1 k header=${lines[1]} 1479 declare -A begin end 1480 while (( j < ${#header} - 1 )); do 1481 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 1482 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 1483 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 1484 begin[${header[$i,$((j-1))]}]=$i 1485 end[${header[$i,$((j-1))]}]=$k 1486 done 1487 end[${header[$i,$((j-1))]}]=-1 1488 lines=(${lines[2,-1]}) 1489 1490 # Name 1491 for line in $lines; do 1492 s="${line[${begin[NAME]},${end[NAME]}]%% ##}" 1493 s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" 1494 plugins=($plugins $s) 1495 done 1496 1497 _describe -t plugins-list "plugins" plugins "$@" && ret=0 1498 return ret 1499 } 1500 1501 __docker_plugin_commands() { 1502 local -a _docker_plugin_subcommands 1503 _docker_plugin_subcommands=( 1504 "disable:Disable a plugin" 1505 "enable:Enable a plugin" 1506 "inspect:Return low-level information about a plugin" 1507 "install:Install a plugin" 1508 "ls:List plugins" 1509 "push:Push a plugin" 1510 "rm:Remove a plugin" 1511 "set:Change settings for a plugin" 1512 ) 1513 _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands 1514 } 1515 1516 __docker_plugin_subcommand() { 1517 local -a _command_args opts_help 1518 local expl help="--help" 1519 integer ret=1 1520 1521 opts_help=("(: -)--help[Print usage]") 1522 1523 case "$words[1]" in 1524 (disable|enable|inspect|ls|push|rm) 1525 _arguments $(__docker_arguments) \ 1526 $opts_help \ 1527 "($help -)1:plugin:__docker_complete_plugins" && ret=0 1528 ;; 1529 (install) 1530 _arguments $(__docker_arguments) \ 1531 $opts_help \ 1532 "($help)--alias=[Local name for plugin]:alias: " \ 1533 "($help -)1:plugin:__docker_complete_plugins" && ret=0 1534 ;; 1535 (set) 1536 _arguments $(__docker_arguments) \ 1537 $opts_help \ 1538 "($help -)1:plugin:__docker_complete_plugins" \ 1539 "($help-)*:key=value: " && ret=0 1540 ;; 1541 (help) 1542 _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 1543 ;; 1544 esac 1545 1546 return ret 1547 } 1548 1549 # EO plugin 1550 1551 # BO secret 1552 1553 __docker_secrets() { 1554 [[ $PREFIX = -* ]] && return 1 1555 integer ret=1 1556 local line s 1557 declare -a lines secrets 1558 1559 type=$1; shift 1560 1561 lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) 1562 1563 # Parse header line to find columns 1564 local i=1 j=1 k header=${lines[1]} 1565 declare -A begin end 1566 while (( j < ${#header} - 1 )); do 1567 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 1568 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 1569 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 1570 begin[${header[$i,$((j-1))]}]=$i 1571 end[${header[$i,$((j-1))]}]=$k 1572 done 1573 end[${header[$i,$((j-1))]}]=-1 1574 lines=(${lines[2,-1]}) 1575 1576 # ID 1577 if [[ $type = (ids|all) ]]; then 1578 for line in $lines; do 1579 s="${line[${begin[ID]},${end[ID]}]%% ##}" 1580 secrets=($secrets $s) 1581 done 1582 fi 1583 1584 # Names 1585 if [[ $type = (names|all) ]]; then 1586 for line in $lines; do 1587 s="${line[${begin[NAME]},${end[NAME]}]%% ##}" 1588 secrets=($secrets $s) 1589 done 1590 fi 1591 1592 _describe -t secrets-list "secrets" secrets "$@" && ret=0 1593 return ret 1594 } 1595 1596 __docker_complete_secrets() { 1597 [[ $PREFIX = -* ]] && return 1 1598 __docker_secrets all "$@" 1599 } 1600 1601 __docker_secret_commands() { 1602 local -a _docker_secret_subcommands 1603 _docker_secret_subcommands=( 1604 "create:Create a secret using stdin as content" 1605 "inspect:Display detailed information on one or more secrets" 1606 "ls:List secrets" 1607 "rm:Remove one or more secrets" 1608 ) 1609 _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands 1610 } 1611 1612 __docker_secret_subcommand() { 1613 local -a _command_args opts_help 1614 local expl help="--help" 1615 integer ret=1 1616 1617 opts_help=("(: -)--help[Print usage]") 1618 1619 case "$words[1]" in 1620 (create) 1621 _arguments $(__docker_arguments) -A '-*' \ 1622 $opts_help \ 1623 "($help)*"{-l=,--label=}"[Secret labels]:label: " \ 1624 "($help -):secret: " && ret=0 1625 ;; 1626 (inspect) 1627 _arguments $(__docker_arguments) \ 1628 $opts_help \ 1629 "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ 1630 "($help -)*:secret:__docker_complete_secrets" && ret=0 1631 ;; 1632 (ls|list) 1633 _arguments $(__docker_arguments) \ 1634 $opts_help \ 1635 "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 1636 ;; 1637 (rm|remove) 1638 _arguments $(__docker_arguments) \ 1639 $opts_help \ 1640 "($help -)*:secret:__docker_complete_secrets" && ret=0 1641 ;; 1642 (help) 1643 _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 1644 ;; 1645 esac 1646 1647 return ret 1648 } 1649 1650 # EO secret 1651 1652 # BO service 1653 1654 __docker_service_complete_ls_filters() { 1655 [[ $PREFIX = -* ]] && return 1 1656 integer ret=1 1657 1658 if compset -P '*='; then 1659 case "${${words[-1]%=*}#*=}" in 1660 (id) 1661 __docker_complete_services_ids && ret=0 1662 ;; 1663 (name) 1664 __docker_complete_services_names && ret=0 1665 ;; 1666 *) 1667 _message 'value' && ret=0 1668 ;; 1669 esac 1670 else 1671 opts=('id' 'label' 'name') 1672 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 1673 fi 1674 1675 return ret 1676 } 1677 1678 __docker_service_complete_ps_filters() { 1679 [[ $PREFIX = -* ]] && return 1 1680 integer ret=1 1681 1682 if compset -P '*='; then 1683 case "${${words[-1]%=*}#*=}" in 1684 (desired-state) 1685 state_opts=('accepted' 'running') 1686 _describe -t state-opts "desired state options" state_opts && ret=0 1687 ;; 1688 *) 1689 _message 'value' && ret=0 1690 ;; 1691 esac 1692 else 1693 opts=('desired-state' 'id' 'label' 'name') 1694 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 1695 fi 1696 1697 return ret 1698 } 1699 1700 __docker_services() { 1701 [[ $PREFIX = -* ]] && return 1 1702 integer ret=1 1703 local line s 1704 declare -a lines services 1705 1706 type=$1; shift 1707 1708 lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) 1709 1710 # Parse header line to find columns 1711 local i=1 j=1 k header=${lines[1]} 1712 declare -A begin end 1713 while (( j < ${#header} - 1 )); do 1714 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 1715 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 1716 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 1717 begin[${header[$i,$((j-1))]}]=$i 1718 end[${header[$i,$((j-1))]}]=$k 1719 done 1720 end[${header[$i,$((j-1))]}]=-1 1721 lines=(${lines[2,-1]}) 1722 1723 # Service ID 1724 if [[ $type = (ids|all) ]]; then 1725 for line in $lines; do 1726 s="${line[${begin[ID]},${end[ID]}]%% ##}" 1727 s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" 1728 services=($services $s) 1729 done 1730 fi 1731 1732 # Names 1733 if [[ $type = (names|all) ]]; then 1734 for line in $lines; do 1735 s="${line[${begin[NAME]},${end[NAME]}]%% ##}" 1736 s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" 1737 services=($services $s) 1738 done 1739 fi 1740 1741 _describe -t services-list "services" services "$@" && ret=0 1742 return ret 1743 } 1744 1745 __docker_complete_services() { 1746 [[ $PREFIX = -* ]] && return 1 1747 __docker_services all "$@" 1748 } 1749 1750 __docker_complete_services_ids() { 1751 [[ $PREFIX = -* ]] && return 1 1752 __docker_services ids "$@" 1753 } 1754 1755 __docker_complete_services_names() { 1756 [[ $PREFIX = -* ]] && return 1 1757 __docker_services names "$@" 1758 } 1759 1760 __docker_service_commands() { 1761 local -a _docker_service_subcommands 1762 _docker_service_subcommands=( 1763 "create:Create a new service" 1764 "inspect:Display detailed information on one or more services" 1765 "ls:List services" 1766 "rm:Remove one or more services" 1767 "scale:Scale one or multiple replicated services" 1768 "ps:List the tasks of a service" 1769 "update:Update a service" 1770 ) 1771 _describe -t docker-service-commands "docker service command" _docker_service_subcommands 1772 } 1773 1774 __docker_service_subcommand() { 1775 local -a _command_args opts_help opts_create_update 1776 local expl help="--help" 1777 integer ret=1 1778 1779 opts_help=("(: -)--help[Print usage]") 1780 opts_create_update=( 1781 "($help)*--constraint=[Placement constraints]:constraint: " 1782 "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" 1783 "($help)*"{-e=,--env=}"[Set environment variables]:env: " 1784 "($help)--health-cmd=[Command to run to check health]:command: " 1785 "($help)--health-interval=[Time between running the check]:time: " 1786 "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" 1787 "($help)--health-timeout=[Maximum time to allow one check to run]:time: " 1788 "($help)--hostname=[Service container hostname]:hostname: " \ 1789 "($help)*--label=[Service labels]:label: " 1790 "($help)--limit-cpu=[Limit CPUs]:value: " 1791 "($help)--limit-memory=[Limit Memory]:value: " 1792 "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" 1793 "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" 1794 "($help)*--mount=[Attach a filesystem mount to the service]:mount: " 1795 "($help)*--network=[Network attachments]:network: " 1796 "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" 1797 "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " 1798 "($help)--replicas=[Number of tasks]:replicas: " 1799 "($help)--reserve-cpu=[Reserve CPUs]:value: " 1800 "($help)--reserve-memory=[Reserve Memory]:value: " 1801 "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" 1802 "($help)--restart-delay=[Delay between restart attempts]:delay: " 1803 "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " 1804 "($help)--restart-window=[Window used to evaluate the restart policy]:window: " 1805 "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" 1806 "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " 1807 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" 1808 "($help)--update-delay=[Delay between updates]:delay: " 1809 "($help)--update-failure-action=[Action on update failure]:mode:(pause continue)" 1810 "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " 1811 "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " 1812 "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " 1813 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" 1814 "($help)--with-registry-auth[Send registry authentication details to swarm agents]" 1815 "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" 1816 ) 1817 1818 case "$words[1]" in 1819 (create) 1820 _arguments $(__docker_arguments) \ 1821 $opts_help \ 1822 $opts_create_update \ 1823 "($help)*--container-label=[Container labels]:label: " \ 1824 "($help)*--dns=[Set custom DNS servers]:DNS: " \ 1825 "($help)*--dns-option=[Set DNS options]:DNS option: " \ 1826 "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ 1827 "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ 1828 "($help)--mode=[Service Mode]:mode:(global replicated)" \ 1829 "($help)--name=[Service name]:name: " \ 1830 "($help)*--publish=[Publish a port]:port: " \ 1831 "($help -): :__docker_complete_images" \ 1832 "($help -):command: _command_names -e" \ 1833 "($help -)*::arguments: _normal" && ret=0 1834 ;; 1835 (inspect) 1836 _arguments $(__docker_arguments) \ 1837 $opts_help \ 1838 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 1839 "($help)--pretty[Print the information in a human friendly format]" \ 1840 "($help -)*:service:__docker_complete_services" && ret=0 1841 ;; 1842 (ls|list) 1843 _arguments $(__docker_arguments) \ 1844 $opts_help \ 1845 "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:->filter-options" \ 1846 "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 1847 case $state in 1848 (filter-options) 1849 __docker_service_complete_ls_filters && ret=0 1850 ;; 1851 esac 1852 ;; 1853 (rm|remove) 1854 _arguments $(__docker_arguments) \ 1855 $opts_help \ 1856 "($help -)*:service:__docker_complete_services" && ret=0 1857 ;; 1858 (scale) 1859 _arguments $(__docker_arguments) \ 1860 $opts_help \ 1861 "($help -)*:service:->values" && ret=0 1862 case $state in 1863 (values) 1864 if compset -P '*='; then 1865 _message 'replicas' && ret=0 1866 else 1867 __docker_complete_services -qS "=" 1868 fi 1869 ;; 1870 esac 1871 ;; 1872 (ps) 1873 _arguments $(__docker_arguments) \ 1874 $opts_help \ 1875 "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ 1876 "($help)--no-resolve[Do not map IDs to Names]" \ 1877 "($help)--no-trunc[Do not truncate output]" \ 1878 "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ 1879 "($help -)1:service:__docker_complete_services" && ret=0 1880 case $state in 1881 (filter-options) 1882 __docker_service_complete_ps_filters && ret=0 1883 ;; 1884 esac 1885 ;; 1886 (update) 1887 _arguments $(__docker_arguments) \ 1888 $opts_help \ 1889 $opts_create_update \ 1890 "($help)--arg=[Service command args]:arguments: _normal" \ 1891 "($help)*--container-label-add=[Add or update container labels]:label: " \ 1892 "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ 1893 "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ 1894 "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ 1895 "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ 1896 "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ 1897 "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ 1898 "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ 1899 "($help)--force[Force update]" \ 1900 "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ 1901 "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ 1902 "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ 1903 "($help)*--publish-add=[Add or update a port]:port: " \ 1904 "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ 1905 "($help)--rollback[Rollback to previous specification]" \ 1906 "($help -)1:service:__docker_complete_services" && ret=0 1907 ;; 1908 (help) 1909 _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 1910 ;; 1911 esac 1912 1913 return ret 1914 } 1915 1916 # EO service 1917 1918 # BO stack 1919 1920 __docker_stack_complete_ps_filters() { 1921 [[ $PREFIX = -* ]] && return 1 1922 integer ret=1 1923 1924 if compset -P '*='; then 1925 case "${${words[-1]%=*}#*=}" in 1926 (desired-state) 1927 state_opts=('accepted' 'running') 1928 _describe -t state-opts "desired state options" state_opts && ret=0 1929 ;; 1930 *) 1931 _message 'value' && ret=0 1932 ;; 1933 esac 1934 else 1935 opts=('desired-state' 'id' 'name') 1936 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 1937 fi 1938 1939 return ret 1940 } 1941 1942 __docker_stack_complete_services_filters() { 1943 [[ $PREFIX = -* ]] && return 1 1944 integer ret=1 1945 1946 if compset -P '*='; then 1947 case "${${words[-1]%=*}#*=}" in 1948 *) 1949 _message 'value' && ret=0 1950 ;; 1951 esac 1952 else 1953 opts=('id' 'label' 'name') 1954 _describe -t filter-opts "filter options" opts -qS "=" && ret=0 1955 fi 1956 1957 return ret 1958 } 1959 1960 __docker_stacks() { 1961 [[ $PREFIX = -* ]] && return 1 1962 integer ret=1 1963 local line s 1964 declare -a lines stacks 1965 1966 lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) 1967 1968 # Parse header line to find columns 1969 local i=1 j=1 k header=${lines[1]} 1970 declare -A begin end 1971 while (( j < ${#header} - 1 )); do 1972 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 1973 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 1974 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 1975 begin[${header[$i,$((j-1))]}]=$i 1976 end[${header[$i,$((j-1))]}]=$k 1977 done 1978 end[${header[$i,$((j-1))]}]=-1 1979 lines=(${lines[2,-1]}) 1980 1981 # Service ID 1982 for line in $lines; do 1983 s="${line[${begin[ID]},${end[ID]}]%% ##}" 1984 stacks=($stacks $s) 1985 done 1986 1987 _describe -t stacks-list "stacks" stacks "$@" && ret=0 1988 return ret 1989 } 1990 1991 __docker_complete_stacks() { 1992 [[ $PREFIX = -* ]] && return 1 1993 __docker_stacks "$@" 1994 } 1995 1996 __docker_stack_commands() { 1997 local -a _docker_stack_subcommands 1998 _docker_stack_subcommands=( 1999 "deploy:Deploy a new stack or update an existing stack" 2000 "ls:List stacks" 2001 "ps:List the tasks in the stack" 2002 "rm:Remove the stack" 2003 "services:List the services in the stack" 2004 ) 2005 _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands 2006 } 2007 2008 __docker_stack_subcommand() { 2009 local -a _command_args opts_help 2010 local expl help="--help" 2011 integer ret=1 2012 2013 opts_help=("(: -)--help[Print usage]") 2014 2015 case "$words[1]" in 2016 (deploy|up) 2017 _arguments $(__docker_arguments) \ 2018 $opts_help \ 2019 "($help)--bundle-file=[Path to a Distributed Application Bundle file]:dab:_files -g \"*.dab\"" \ 2020 "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file]:compose file:_files -g \"*.(yml|yaml)\"" \ 2021 "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ 2022 "($help -):stack:__docker_complete_stacks" && ret=0 2023 ;; 2024 (ls|list) 2025 _arguments $(__docker_arguments) \ 2026 $opts_help && ret=0 2027 ;; 2028 (ps) 2029 _arguments $(__docker_arguments) \ 2030 $opts_help \ 2031 "($help -a --all)"{-a,--all}"[Display all tasks]" \ 2032 "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ 2033 "($help)--no-resolve[Do not map IDs to Names]" \ 2034 "($help)--no-trunc[Do not truncate output]" \ 2035 "($help -):stack:__docker_complete_stacks" && ret=0 2036 ;; 2037 (rm|remove|down) 2038 _arguments $(__docker_arguments) \ 2039 $opts_help \ 2040 "($help -):stack:__docker_complete_stacks" && ret=0 2041 ;; 2042 (services) 2043 _arguments $(__docker_arguments) \ 2044 $opts_help \ 2045 "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ 2046 "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ 2047 "($help -):stack:__docker_complete_stacks" && ret=0 2048 ;; 2049 (help) 2050 _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 2051 ;; 2052 esac 2053 2054 return ret 2055 } 2056 2057 # EO stack 2058 2059 # BO swarm 2060 2061 __docker_swarm_commands() { 2062 local -a _docker_swarm_subcommands 2063 _docker_swarm_subcommands=( 2064 "init:Initialize a swarm" 2065 "join:Join a swarm as a node and/or manager" 2066 "join-token:Manage join tokens" 2067 "leave:Leave a swarm" 2068 "update:Update the swarm" 2069 ) 2070 _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands 2071 } 2072 2073 __docker_swarm_subcommand() { 2074 local -a _command_args opts_help 2075 local expl help="--help" 2076 integer ret=1 2077 2078 opts_help=("(: -)--help[Print usage]") 2079 2080 case "$words[1]" in 2081 (init) 2082 _arguments $(__docker_arguments) \ 2083 $opts_help \ 2084 "($help)--advertise-addr[Advertised address]:ip\:port: " \ 2085 "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ 2086 "($help)--force-new-cluster[Force create a new cluster from current state]" \ 2087 "($help)--listen-addr=[Listen address]:ip\:port: " \ 2088 "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ 2089 "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ 2090 "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 2091 ;; 2092 (join) 2093 _arguments $(__docker_arguments) -A '-*' \ 2094 $opts_help \ 2095 "($help)--advertise-addr=[Advertised address]:ip\:port: " \ 2096 "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ 2097 "($help)--listen-addr=[Listen address]:ip\:port: " \ 2098 "($help)--token=[Token for entry into the swarm]:secret: " \ 2099 "($help -):host\:port: " && ret=0 2100 ;; 2101 (join-token) 2102 _arguments $(__docker_arguments) \ 2103 $opts_help \ 2104 "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ 2105 "($help)--rotate[Rotate join token]" \ 2106 "($help -):role:(manager worker)" && ret=0 2107 ;; 2108 (leave) 2109 _arguments $(__docker_arguments) \ 2110 $opts_help \ 2111 "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 2112 ;; 2113 (update) 2114 _arguments $(__docker_arguments) \ 2115 $opts_help \ 2116 "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ 2117 "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ 2118 "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ 2119 "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ 2120 "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ 2121 "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 2122 ;; 2123 (help) 2124 _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 2125 ;; 2126 esac 2127 2128 return ret 2129 } 2130 2131 # EO swarm 2132 2133 # BO system 2134 2135 __docker_system_commands() { 2136 local -a _docker_system_subcommands 2137 _docker_system_subcommands=( 2138 "df:Show docker filesystem usage" 2139 "events:Get real time events from the server" 2140 "info:Display system-wide information" 2141 "prune:Remove unused data" 2142 ) 2143 _describe -t docker-system-commands "docker system command" _docker_system_subcommands 2144 } 2145 2146 __docker_system_subcommand() { 2147 local -a _command_args opts_help 2148 local expl help="--help" 2149 integer ret=1 2150 2151 opts_help=("(: -)--help[Print usage]") 2152 2153 case "$words[1]" in 2154 (df) 2155 _arguments $(__docker_arguments) \ 2156 $opts_help \ 2157 "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 2158 ;; 2159 (events) 2160 _arguments $(__docker_arguments) \ 2161 $opts_help \ 2162 "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ 2163 "($help)--since=[Events created since this timestamp]:timestamp: " \ 2164 "($help)--until=[Events created until this timestamp]:timestamp: " \ 2165 "($help)--format=[Format the output using the given go template]:template: " && ret=0 2166 ;; 2167 (info) 2168 _arguments $(__docker_arguments) \ 2169 $opts_help \ 2170 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 2171 ;; 2172 (prune) 2173 _arguments $(__docker_arguments) \ 2174 $opts_help \ 2175 "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ 2176 "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ 2177 "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 2178 ;; 2179 (help) 2180 _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 2181 ;; 2182 esac 2183 2184 return ret 2185 } 2186 2187 # EO system 2188 2189 # BO volume 2190 2191 __docker_volume_complete_ls_filters() { 2192 [[ $PREFIX = -* ]] && return 1 2193 integer ret=1 2194 2195 if compset -P '*='; then 2196 case "${${words[-1]%=*}#*=}" in 2197 (dangling) 2198 dangling_opts=('true' 'false') 2199 _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 2200 ;; 2201 (driver) 2202 __docker_complete_info_plugins Volume && ret=0 2203 ;; 2204 (name) 2205 __docker_complete_volumes && ret=0 2206 ;; 2207 *) 2208 _message 'value' && ret=0 2209 ;; 2210 esac 2211 else 2212 opts=('dangling' 'driver' 'label' 'name') 2213 _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 2214 fi 2215 2216 return ret 2217 } 2218 2219 __docker_complete_volumes() { 2220 [[ $PREFIX = -* ]] && return 1 2221 integer ret=1 2222 declare -a lines volumes 2223 2224 lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) 2225 2226 # Parse header line to find columns 2227 local i=1 j=1 k header=${lines[1]} 2228 declare -A begin end 2229 while (( j < ${#header} - 1 )); do 2230 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 2231 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 2232 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 2233 begin[${header[$i,$((j-1))]}]=$i 2234 end[${header[$i,$((j-1))]}]=$k 2235 done 2236 end[${header[$i,$((j-1))]}]=-1 2237 lines=(${lines[2,-1]}) 2238 2239 # Names 2240 local line s 2241 for line in $lines; do 2242 s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" 2243 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 2244 volumes=($volumes $s) 2245 done 2246 2247 _describe -t volumes-list "volumes" volumes && ret=0 2248 return ret 2249 } 2250 2251 __docker_volume_commands() { 2252 local -a _docker_volume_subcommands 2253 _docker_volume_subcommands=( 2254 "create:Create a volume" 2255 "inspect:Display detailed information on one or more volumes" 2256 "ls:List volumes" 2257 "prune:Remove all unused volumes" 2258 "rm:Remove one or more volumes" 2259 ) 2260 _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands 2261 } 2262 2263 __docker_volume_subcommand() { 2264 local -a _command_args opts_help 2265 local expl help="--help" 2266 integer ret=1 2267 2268 opts_help=("(: -)--help[Print usage]") 2269 2270 case "$words[1]" in 2271 (create) 2272 _arguments $(__docker_arguments) -A '-*' \ 2273 $opts_help \ 2274 "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ 2275 "($help)*--label=[Set metadata for a volume]:label=value: " \ 2276 "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ 2277 "($help -)1:Volume name: " && ret=0 2278 ;; 2279 (inspect) 2280 _arguments $(__docker_arguments) \ 2281 $opts_help \ 2282 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 2283 "($help -)1:volume:__docker_complete_volumes" && ret=0 2284 ;; 2285 (ls) 2286 _arguments $(__docker_arguments) \ 2287 $opts_help \ 2288 "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ 2289 "($help)--format=[Pretty-print volumes using a Go template]:template: " \ 2290 "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 2291 case $state in 2292 (filter-options) 2293 __docker_volume_complete_ls_filters && ret=0 2294 ;; 2295 esac 2296 ;; 2297 (prune) 2298 _arguments $(__docker_arguments) \ 2299 $opts_help \ 2300 "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 2301 ;; 2302 (rm) 2303 _arguments $(__docker_arguments) \ 2304 $opts_help \ 2305 "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ 2306 "($help -):volume:__docker_complete_volumes" && ret=0 2307 ;; 2308 (help) 2309 _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 2310 ;; 2311 esac 2312 2313 return ret 2314 } 2315 2316 # EO volume 2317 2318 __docker_caching_policy() { 2319 oldp=( "$1"(Nmh+1) ) # 1 hour 2320 (( $#oldp )) 2321 } 2322 2323 __docker_commands() { 2324 local cache_policy 2325 2326 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 2327 if [[ -z "$cache_policy" ]]; then 2328 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 2329 fi 2330 2331 if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ 2332 && ! _retrieve_cache docker_subcommands; 2333 then 2334 local -a lines 2335 lines=(${(f)"$(_call_program commands docker 2>&1)"}) 2336 _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/ ##/:}) 2337 _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') 2338 (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands 2339 fi 2340 _describe -t docker-commands "docker command" _docker_subcommands 2341 } 2342 2343 __docker_subcommand() { 2344 local -a _command_args opts_help 2345 local expl help="--help" 2346 integer ret=1 2347 2348 opts_help=("(: -)--help[Print usage]") 2349 2350 case "$words[1]" in 2351 (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) 2352 __docker_container_subcommand && ret=0 2353 ;; 2354 (build|history|import|load|pull|push|save|tag) 2355 __docker_image_subcommand && ret=0 2356 ;; 2357 (container) 2358 local curcontext="$curcontext" state 2359 _arguments $(__docker_arguments) \ 2360 $opts_help \ 2361 "($help -): :->command" \ 2362 "($help -)*:: :->option-or-argument" && ret=0 2363 2364 case $state in 2365 (command) 2366 __docker_container_commands && ret=0 2367 ;; 2368 (option-or-argument) 2369 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2370 __docker_container_subcommand && ret=0 2371 ;; 2372 esac 2373 ;; 2374 (daemon) 2375 _arguments $(__docker_arguments) \ 2376 $opts_help \ 2377 "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ 2378 "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ 2379 "($help)*--authorization-plugin=[Authorization plugins to load]" \ 2380 "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ 2381 "($help)--bip=[Network bridge IP]:IP address: " \ 2382 "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ 2383 "($help)--cluster-advertise=[Address or interface name to advertise]:Instance to advertise (host\:port): " \ 2384 "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \ 2385 "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \ 2386 "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ 2387 "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ 2388 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 2389 "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ 2390 "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ 2391 "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ 2392 "($help)--disable-legacy-registry[Disable contacting legacy registries]" \ 2393 "($help)*--dns=[DNS server to use]:DNS: " \ 2394 "($help)*--dns-opt=[DNS options to use]:DNS option: " \ 2395 "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ 2396 "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ 2397 "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ 2398 "($help)--experimental[Enable experimental features]" \ 2399 "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ 2400 "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ 2401 "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ 2402 "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \ 2403 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 2404 "($help)--icc[Enable inter-container communication]" \ 2405 "($help)--init[Run an init inside containers to forward signals and reap processes]" \ 2406 "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ 2407 "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ 2408 "($help)--ip=[Default IP when binding container ports]" \ 2409 "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ 2410 "($help)--ip-masq[Enable IP masquerading]" \ 2411 "($help)--iptables[Enable addition of iptables rules]" \ 2412 "($help)--ipv6[Enable IPv6 networking]" \ 2413 "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ 2414 "($help)*--label=[Key=value labels]:label: " \ 2415 "($help)--live-restore[Enable live restore of docker when containers are still running]" \ 2416 "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ 2417 "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ 2418 "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \ 2419 "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \ 2420 "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ 2421 "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ 2422 "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ 2423 "($help)--raw-logs[Full timestamps without ANSI coloring]" \ 2424 "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \ 2425 "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ 2426 "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \ 2427 "($help)--selinux-enabled[Enable selinux support]" \ 2428 "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ 2429 "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ 2430 "($help)--tls[Use TLS]" \ 2431 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ 2432 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ 2433 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ 2434 "($help)--tlsverify[Use TLS and verify the remote]" \ 2435 "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ 2436 "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ 2437 "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" && ret=0 2438 2439 case $state in 2440 (cluster-store) 2441 if compset -P '*://'; then 2442 _message 'host:port' && ret=0 2443 else 2444 store=('consul' 'etcd' 'zk') 2445 _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0 2446 fi 2447 ;; 2448 (cluster-store-options) 2449 if compset -P '*='; then 2450 _files && ret=0 2451 else 2452 opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path') 2453 _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0 2454 fi 2455 ;; 2456 (users-groups) 2457 if compset -P '*:'; then 2458 _groups && ret=0 2459 else 2460 _describe -t userns-default "default Docker user management" '(default)' && ret=0 2461 _users && ret=0 2462 fi 2463 ;; 2464 esac 2465 ;; 2466 (events|info) 2467 __docker_system_subcommand && ret=0 2468 ;; 2469 (image) 2470 local curcontext="$curcontext" state 2471 _arguments $(__docker_arguments) \ 2472 $opts_help \ 2473 "($help -): :->command" \ 2474 "($help -)*:: :->option-or-argument" && ret=0 2475 2476 case $state in 2477 (command) 2478 __docker_image_commands && ret=0 2479 ;; 2480 (option-or-argument) 2481 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2482 __docker_image_subcommand && ret=0 2483 ;; 2484 esac 2485 ;; 2486 (images) 2487 words[1]='ls' 2488 __docker_image_subcommand && ret=0 2489 ;; 2490 (inspect) 2491 local state 2492 _arguments $(__docker_arguments) \ 2493 $opts_help \ 2494 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 2495 "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ 2496 "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ 2497 "($help -)*: :->values" && ret=0 2498 2499 case $state in 2500 (values) 2501 if [[ ${words[(r)--type=container]} == --type=container ]]; then 2502 __docker_complete_containers && ret=0 2503 elif [[ ${words[(r)--type=image]} == --type=image ]]; then 2504 __docker_complete_images && ret=0 2505 elif [[ ${words[(r)--type=network]} == --type=network ]]; then 2506 __docker_complete_networks && ret=0 2507 elif [[ ${words[(r)--type=node]} == --type=node ]]; then 2508 __docker_complete_nodes && ret=0 2509 elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then 2510 __docker_complete_plugins && ret=0 2511 elif [[ ${words[(r)--type=service]} == --type=service ]]; then 2512 __docker_complete_services && ret=0 2513 elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then 2514 __docker_complete_volumes && ret=0 2515 else 2516 __docker_complete_containers 2517 __docker_complete_images 2518 __docker_complete_networks 2519 __docker_complete_nodes 2520 __docker_complete_plugins 2521 __docker_complete_services 2522 __docker_complete_volumes && ret=0 2523 fi 2524 ;; 2525 esac 2526 ;; 2527 (login) 2528 _arguments $(__docker_arguments) -A '-*' \ 2529 $opts_help \ 2530 "($help -p --password)"{-p=,--password=}"[Password]:password: " \ 2531 "($help -u --user)"{-u=,--user=}"[Username]:username: " \ 2532 "($help -)1:server: " && ret=0 2533 ;; 2534 (logout) 2535 _arguments $(__docker_arguments) -A '-*' \ 2536 $opts_help \ 2537 "($help -)1:server: " && ret=0 2538 ;; 2539 (network) 2540 local curcontext="$curcontext" state 2541 _arguments $(__docker_arguments) \ 2542 $opts_help \ 2543 "($help -): :->command" \ 2544 "($help -)*:: :->option-or-argument" && ret=0 2545 2546 case $state in 2547 (command) 2548 __docker_network_commands && ret=0 2549 ;; 2550 (option-or-argument) 2551 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2552 __docker_network_subcommand && ret=0 2553 ;; 2554 esac 2555 ;; 2556 (node) 2557 local curcontext="$curcontext" state 2558 _arguments $(__docker_arguments) \ 2559 $opts_help \ 2560 "($help -): :->command" \ 2561 "($help -)*:: :->option-or-argument" && ret=0 2562 2563 case $state in 2564 (command) 2565 __docker_node_commands && ret=0 2566 ;; 2567 (option-or-argument) 2568 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2569 __docker_node_subcommand && ret=0 2570 ;; 2571 esac 2572 ;; 2573 (plugin) 2574 local curcontext="$curcontext" state 2575 _arguments $(__docker_arguments) \ 2576 $opts_help \ 2577 "($help -): :->command" \ 2578 "($help -)*:: :->option-or-argument" && ret=0 2579 2580 case $state in 2581 (command) 2582 __docker_plugin_commands && ret=0 2583 ;; 2584 (option-or-argument) 2585 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2586 __docker_plugin_subcommand && ret=0 2587 ;; 2588 esac 2589 ;; 2590 (ps) 2591 words[1]='ls' 2592 __docker_container_subcommand && ret=0 2593 ;; 2594 (rmi) 2595 words[1]='rm' 2596 __docker_image_subcommand && ret=0 2597 ;; 2598 (search) 2599 _arguments $(__docker_arguments) -A '-*' \ 2600 $opts_help \ 2601 "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ 2602 "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ 2603 "($help)--no-trunc[Do not truncate output]" \ 2604 "($help -):term: " && ret=0 2605 2606 case $state in 2607 (filter-options) 2608 __docker_complete_search_filters && ret=0 2609 ;; 2610 esac 2611 ;; 2612 (secret) 2613 local curcontext="$curcontext" state 2614 _arguments $(__docker_arguments) \ 2615 $opts_help \ 2616 "($help -): :->command" \ 2617 "($help -)*:: :->option-or-argument" && ret=0 2618 2619 case $state in 2620 (command) 2621 __docker_secret_commands && ret=0 2622 ;; 2623 (option-or-argument) 2624 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2625 __docker_secret_subcommand && ret=0 2626 ;; 2627 esac 2628 ;; 2629 (service) 2630 local curcontext="$curcontext" state 2631 _arguments $(__docker_arguments) \ 2632 $opts_help \ 2633 "($help -): :->command" \ 2634 "($help -)*:: :->option-or-argument" && ret=0 2635 2636 case $state in 2637 (command) 2638 __docker_service_commands && ret=0 2639 ;; 2640 (option-or-argument) 2641 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2642 __docker_service_subcommand && ret=0 2643 ;; 2644 esac 2645 ;; 2646 (stack) 2647 local curcontext="$curcontext" state 2648 _arguments $(__docker_arguments) \ 2649 $opts_help \ 2650 "($help -): :->command" \ 2651 "($help -)*:: :->option-or-argument" && ret=0 2652 2653 case $state in 2654 (command) 2655 __docker_stack_commands && ret=0 2656 ;; 2657 (option-or-argument) 2658 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2659 __docker_stack_subcommand && ret=0 2660 ;; 2661 esac 2662 ;; 2663 (swarm) 2664 local curcontext="$curcontext" state 2665 _arguments $(__docker_arguments) \ 2666 $opts_help \ 2667 "($help -): :->command" \ 2668 "($help -)*:: :->option-or-argument" && ret=0 2669 2670 case $state in 2671 (command) 2672 __docker_swarm_commands && ret=0 2673 ;; 2674 (option-or-argument) 2675 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2676 __docker_swarm_subcommand && ret=0 2677 ;; 2678 esac 2679 ;; 2680 (system) 2681 local curcontext="$curcontext" state 2682 _arguments $(__docker_arguments) \ 2683 $opts_help \ 2684 "($help -): :->command" \ 2685 "($help -)*:: :->option-or-argument" && ret=0 2686 2687 case $state in 2688 (command) 2689 __docker_system_commands && ret=0 2690 ;; 2691 (option-or-argument) 2692 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2693 __docker_system_subcommand && ret=0 2694 ;; 2695 esac 2696 ;; 2697 (version) 2698 _arguments $(__docker_arguments) \ 2699 $opts_help \ 2700 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 2701 ;; 2702 (volume) 2703 local curcontext="$curcontext" state 2704 _arguments $(__docker_arguments) \ 2705 $opts_help \ 2706 "($help -): :->command" \ 2707 "($help -)*:: :->option-or-argument" && ret=0 2708 2709 case $state in 2710 (command) 2711 __docker_volume_commands && ret=0 2712 ;; 2713 (option-or-argument) 2714 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 2715 __docker_volume_subcommand && ret=0 2716 ;; 2717 esac 2718 ;; 2719 (help) 2720 _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 2721 ;; 2722 esac 2723 2724 return ret 2725 } 2726 2727 _docker() { 2728 # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. 2729 # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. 2730 if [[ $service != docker ]]; then 2731 _call_function - _$service 2732 return 2733 fi 2734 2735 local curcontext="$curcontext" state line help="-h --help" 2736 integer ret=1 2737 typeset -A opt_args 2738 2739 _arguments $(__docker_arguments) -C \ 2740 "(: -)"{-h,--help}"[Print usage]" \ 2741 "($help)--config[Location of client config files]:path:_directories" \ 2742 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 2743 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 2744 "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ 2745 "($help)--tls[Use TLS]" \ 2746 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ 2747 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ 2748 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ 2749 "($help)--tlsverify[Use TLS and verify the remote]" \ 2750 "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ 2751 "($help -v --version)"{-v,--version}"[Print version information and quit]" \ 2752 "($help -): :->command" \ 2753 "($help -)*:: :->option-or-argument" && ret=0 2754 2755 local host=${opt_args[-H]}${opt_args[--host]} 2756 local config=${opt_args[--config]} 2757 local docker_options="${host:+--host $host} ${config:+--config $config}" 2758 2759 case $state in 2760 (command) 2761 __docker_commands && ret=0 2762 ;; 2763 (option-or-argument) 2764 curcontext=${curcontext%:*:*}:docker-$words[1]: 2765 __docker_subcommand && ret=0 2766 ;; 2767 esac 2768 2769 return ret 2770 } 2771 2772 _dockerd() { 2773 integer ret=1 2774 words[1]='daemon' 2775 __docker_subcommand && ret=0 2776 return ret 2777 } 2778 2779 _docker "$@" 2780 2781 # Local Variables: 2782 # mode: Shell-Script 2783 # sh-indentation: 4 2784 # indent-tabs-mode: nil 2785 # sh-basic-offset: 4 2786 # End: 2787 # vim: ft=zsh sw=4 ts=4 et