github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/contrib/completion/zsh/_docker (about) 1 #compdef docker 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 --no-trunc $args)"}) 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_stoppedcontainers() { 117 [[ $PREFIX = -* ]] && return 1 118 __docker_get_containers stopped all "$@" 119 } 120 121 __docker_runningcontainers() { 122 [[ $PREFIX = -* ]] && return 1 123 __docker_get_containers running all "$@" 124 } 125 126 __docker_containers() { 127 [[ $PREFIX = -* ]] && return 1 128 __docker_get_containers all all "$@" 129 } 130 131 __docker_containers_ids() { 132 [[ $PREFIX = -* ]] && return 1 133 __docker_get_containers all ids "$@" 134 } 135 136 __docker_containers_names() { 137 [[ $PREFIX = -* ]] && return 1 138 __docker_get_containers all names "$@" 139 } 140 141 __docker_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_images() { 153 [[ $PREFIX = -* ]] && return 1 154 integer ret=1 155 declare -a images 156 images=(${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) 157 _describe -t docker-images "images" images && ret=0 158 __docker_repositories_with_tags && ret=0 159 return ret 160 } 161 162 __docker_repositories() { 163 [[ $PREFIX = -* ]] && return 1 164 declare -a repos 165 repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]}) 166 repos=(${repos#<none>}) 167 _describe -t docker-repos "repositories" repos 168 } 169 170 __docker_repositories_with_tags() { 171 [[ $PREFIX = -* ]] && return 1 172 integer ret=1 173 declare -a repos onlyrepos matched 174 declare m 175 repos=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/:::}%% *}) 176 repos=(${${repos%:::<none>}#<none>}) 177 # Check if we have a prefix-match for the current prefix. 178 onlyrepos=(${repos%::*}) 179 for m in $onlyrepos; do 180 [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { 181 # Yes, complete with tags 182 repos=(${${repos/:::/:}/:/\\:}) 183 _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 184 return ret 185 } 186 done 187 # No, only complete repositories 188 onlyrepos=(${${repos%:::*}/:/\\:}) 189 _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 190 191 return ret 192 } 193 194 __docker_search() { 195 [[ $PREFIX = -* ]] && return 1 196 local cache_policy 197 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 198 if [[ -z "$cache_policy" ]]; then 199 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 200 fi 201 202 local searchterm cachename 203 searchterm="${words[$CURRENT]%/}" 204 cachename=_docker-search-$searchterm 205 206 local expl 207 local -a result 208 if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ 209 && ! _retrieve_cache ${cachename#_}; then 210 _message "Searching for ${searchterm}..." 211 result=(${${${(f)"$(_call_program commands docker $docker_options search $searchterm)"}%% *}[2,-1]}) 212 _store_cache ${cachename#_} result 213 fi 214 _wanted dockersearch expl 'available images' compadd -a result 215 } 216 217 __docker_get_log_options() { 218 [[ $PREFIX = -* ]] && return 1 219 220 integer ret=1 221 local log_driver=${opt_args[--log-driver]:-"all"} 222 local -a awslogs_options fluentd_options gelf_options journald_options json_file_options syslog_options splunk_options 223 224 awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream") 225 fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag") 226 gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels") 227 gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag") 228 journald_options=("env" "labels" "tag") 229 json_file_options=("env" "labels" "max-file" "max-size") 230 syslog_options=("syslog-address" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "syslog-facility" "tag") 231 splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "tag") 232 233 [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 234 [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 235 [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 236 [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 237 [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 238 [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 239 [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 240 [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 241 242 return ret 243 } 244 245 __docker_log_options() { 246 [[ $PREFIX = -* ]] && return 1 247 integer ret=1 248 249 if compset -P '*='; then 250 case "${${words[-1]%=*}#*=}" in 251 (syslog-format) 252 syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro') 253 _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0 254 ;; 255 *) 256 _message 'value' && ret=0 257 ;; 258 esac 259 else 260 __docker_get_log_options -qS "=" && ret=0 261 fi 262 263 return ret 264 } 265 266 __docker_complete_detach_keys() { 267 [[ $PREFIX = -* ]] && return 1 268 integer ret=1 269 270 compset -P "*," 271 keys=(${:-{a-z}}) 272 ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) 273 _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 274 _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 275 } 276 277 __docker_complete_ps_filters() { 278 [[ $PREFIX = -* ]] && return 1 279 integer ret=1 280 281 if compset -P '*='; then 282 case "${${words[-1]%=*}#*=}" in 283 (ancestor) 284 __docker_images && ret=0 285 ;; 286 (before|since) 287 __docker_containers && ret=0 288 ;; 289 (id) 290 __docker_containers_ids && ret=0 291 ;; 292 (name) 293 __docker_containers_names && ret=0 294 ;; 295 (status) 296 status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running') 297 _describe -t status-filter-opts "Status Filter Options" status_opts && ret=0 298 ;; 299 (volume) 300 __docker_volumes && ret=0 301 ;; 302 *) 303 _message 'value' && ret=0 304 ;; 305 esac 306 else 307 opts=('ancestor' 'before' 'exited' 'id' 'label' 'name' 'since' 'status' 'volume') 308 _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 309 fi 310 311 return ret 312 } 313 314 __docker_networks() { 315 [[ $PREFIX = -* ]] && return 1 316 integer ret=1 317 declare -a lines networks 318 319 lines=(${(f)"$(_call_program commands docker $docker_options network ls)"}) 320 321 # Parse header line to find columns 322 local i=1 j=1 k header=${lines[1]} 323 declare -A begin end 324 while (( j < ${#header} - 1 )); do 325 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 326 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 327 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 328 begin[${header[$i,$((j-1))]}]=$i 329 end[${header[$i,$((j-1))]}]=$k 330 done 331 end[${header[$i,$((j-1))]}]=-1 332 lines=(${lines[2,-1]}) 333 334 # Network ID 335 local line s 336 for line in $lines; do 337 s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" 338 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 339 networks=($networks $s) 340 done 341 342 # Names 343 for line in $lines; do 344 s="${line[${begin[NAME]},${end[NAME]}]%% ##}" 345 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 346 networks=($networks $s) 347 done 348 349 _describe -t networks-list "networks" networks && ret=0 350 return ret 351 } 352 353 __docker_network_commands() { 354 local -a _docker_network_subcommands 355 _docker_network_subcommands=( 356 "connect:onnects a container to a network" 357 "create:Creates a new network with a name specified by the user" 358 "disconnect:Disconnects a container from a network" 359 "inspect:Displays detailed information on a network" 360 "ls:Lists all the networks created by the user" 361 "rm:Deletes one or more networks" 362 ) 363 _describe -t docker-network-commands "docker network command" _docker_network_subcommands 364 } 365 366 __docker_network_subcommand() { 367 local -a _command_args opts_help 368 local expl help="--help" 369 integer ret=1 370 371 opts_help=("(: -)--help[Print usage]") 372 373 case "$words[1]" in 374 (connect) 375 _arguments $(__docker_arguments) \ 376 $opts_help \ 377 "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ 378 "($help)--ip=[Container IPv4 address]:IPv4: " \ 379 "($help)--ip6=[Container IPv6 address]:IPv6: " \ 380 "($help)*--link=[Add a link to another container]:link:->link" \ 381 "($help -)1:network:__docker_networks" \ 382 "($help -)2:containers:__docker_containers" && ret=0 383 384 case $state in 385 (link) 386 if compset -P "*:"; then 387 _wanted alias expl "Alias" compadd -E "" && ret=0 388 else 389 __docker_runningcontainers -qS ":" && ret=0 390 fi 391 ;; 392 esac 393 ;; 394 (create) 395 _arguments $(__docker_arguments) -A '-*' \ 396 $opts_help \ 397 "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ 398 "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ 399 "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ 400 "($help)--internal[Restricts external access to the network]" \ 401 "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ 402 "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ 403 "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ 404 "($help)--ipv6[Enable IPv6 networking]" \ 405 "($help)*--label=[Set metadata on a network]:label=value: " \ 406 "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ 407 "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ 408 "($help -)1:Network Name: " && ret=0 409 ;; 410 (disconnect) 411 _arguments $(__docker_arguments) \ 412 $opts_help \ 413 "($help -)1:network:__docker_networks" \ 414 "($help -)2:containers:__docker_containers" && ret=0 415 ;; 416 (inspect) 417 _arguments $(__docker_arguments) \ 418 $opts_help \ 419 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 420 "($help -)*:network:__docker_networks" && ret=0 421 ;; 422 (ls) 423 _arguments $(__docker_arguments) \ 424 $opts_help \ 425 "($help)--no-trunc[Do not truncate the output]" \ 426 "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0 427 ;; 428 (rm) 429 _arguments $(__docker_arguments) \ 430 $opts_help \ 431 "($help -)*:network:__docker_networks" && ret=0 432 ;; 433 (help) 434 _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 435 ;; 436 esac 437 438 return ret 439 } 440 441 __docker_volume_complete_ls_filters() { 442 [[ $PREFIX = -* ]] && return 1 443 integer ret=1 444 445 if compset -P '*='; then 446 case "${${words[-1]%=*}#*=}" in 447 (dangling) 448 dangling_opts=('true' 'false') 449 _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 450 ;; 451 (driver) 452 __docker_plugins Volume && ret=0 453 ;; 454 (name) 455 __docker_volumes && ret=0 456 ;; 457 *) 458 _message 'value' && ret=0 459 ;; 460 esac 461 else 462 opts=('dangling' 'driver' 'name') 463 _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 464 fi 465 466 return ret 467 } 468 469 __docker_volumes() { 470 [[ $PREFIX = -* ]] && return 1 471 integer ret=1 472 declare -a lines volumes 473 474 lines=(${(f)"$(_call_program commands docker $docker_options volume ls)"}) 475 476 # Parse header line to find columns 477 local i=1 j=1 k header=${lines[1]} 478 declare -A begin end 479 while (( j < ${#header} - 1 )); do 480 i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 481 j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 482 k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 483 begin[${header[$i,$((j-1))]}]=$i 484 end[${header[$i,$((j-1))]}]=$k 485 done 486 end[${header[$i,$((j-1))]}]=-1 487 lines=(${lines[2,-1]}) 488 489 # Names 490 local line s 491 for line in $lines; do 492 s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" 493 s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" 494 volumes=($volumes $s) 495 done 496 497 _describe -t volumes-list "volumes" volumes && ret=0 498 return ret 499 } 500 501 __docker_volume_commands() { 502 local -a _docker_volume_subcommands 503 _docker_volume_subcommands=( 504 "create:Create a volume" 505 "inspect:Return low-level information on a volume" 506 "ls:List volumes" 507 "rm:Remove a volume" 508 ) 509 _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands 510 } 511 512 __docker_volume_subcommand() { 513 local -a _command_args opts_help 514 local expl help="--help" 515 integer ret=1 516 517 opts_help=("(: -)--help[Print usage]") 518 519 case "$words[1]" in 520 (create) 521 _arguments $(__docker_arguments) \ 522 $opts_help \ 523 "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ 524 "($help)*--label=[Set metadata for a volume]:label=value: " \ 525 "($help)--name=[Volume name]" \ 526 "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " && ret=0 527 ;; 528 (inspect) 529 _arguments $(__docker_arguments) \ 530 $opts_help \ 531 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 532 "($help -)1:volume:__docker_volumes" && ret=0 533 ;; 534 (ls) 535 _arguments $(__docker_arguments) \ 536 $opts_help \ 537 "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ 538 "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 539 case $state in 540 (filter-options) 541 __docker_volume_complete_ls_filters && ret=0 542 ;; 543 esac 544 ;; 545 (rm) 546 _arguments $(__docker_arguments) \ 547 $opts_help \ 548 "($help -):volume:__docker_volumes" && ret=0 549 ;; 550 (help) 551 _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 552 ;; 553 esac 554 555 return ret 556 } 557 558 __docker_caching_policy() { 559 oldp=( "$1"(Nmh+1) ) # 1 hour 560 (( $#oldp )) 561 } 562 563 __docker_commands() { 564 local cache_policy 565 566 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 567 if [[ -z "$cache_policy" ]]; then 568 zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy 569 fi 570 571 if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ 572 && ! _retrieve_cache docker_subcommands; 573 then 574 local -a lines 575 lines=(${(f)"$(_call_program commands docker 2>&1)"}) 576 _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) 577 _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') 578 (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands 579 fi 580 _describe -t docker-commands "docker command" _docker_subcommands 581 } 582 583 __docker_subcommand() { 584 local -a _command_args opts_help opts_build_create_run opts_build_create_run_update opts_create_run opts_create_run_update 585 local expl help="--help" 586 integer ret=1 587 588 opts_help=("(: -)--help[Print usage]") 589 opts_build_create_run=( 590 "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " 591 "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" 592 "($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: " 593 "($help)*--ulimit=[ulimit options]:ulimit: " 594 "($help)--userns=[Container user namespace]:user namespace:(host)" 595 ) 596 opts_build_create_run_update=( 597 "($help)--cpu-shares=[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" 598 "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " 599 "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " 600 "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " 601 "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " 602 "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " 603 "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " 604 ) 605 opts_create_run=( 606 "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" 607 "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " 608 "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " 609 "($help)*--cap-add=[Add Linux capabilities]:capability: " 610 "($help)*--cap-drop=[Drop Linux capabilities]:capability: " 611 "($help)--cidfile=[Write the container ID to the file]:CID file:_files" 612 "($help)*--device=[Add a host device to the container]:device:_files" 613 "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " 614 "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " 615 "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " 616 "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " 617 "($help)*--dns=[Custom DNS servers]:DNS server: " 618 "($help)*--dns-opt=[Custom DNS options]:DNS option: " 619 "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " 620 "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " 621 "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " 622 "($help)*--env-file=[Read environment variables from a file]:environment file:_files" 623 "($help)*--expose=[Expose a port from the container without publishing it]: " 624 "($help)*--group-add=[Add additional groups to run as]:group:_groups" 625 "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" 626 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" 627 "($help)--ip=[Container IPv4 address]:IPv4: " 628 "($help)--ip6=[Container IPv6 address]:IPv6: " 629 "($help)--ipc=[IPC namespace to use]:IPC namespace: " 630 "($help)*--link=[Add link to another container]:link:->link" 631 "($help)*"{-l=,--label=}"[Container metadata]:label: " 632 "($help)--log-driver=[Default driver for container logs]:Logging driver:(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog)" 633 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" 634 "($help)--mac-address=[Container MAC address]:MAC address: " 635 "($help)--name=[Container name]:name: " 636 "($help)--net=[Connect a container to a network]:network mode:(bridge none container host)" 637 "($help)*--net-alias=[Add network-scoped alias for the container]:alias: " 638 "($help)--oom-kill-disable[Disable OOM Killer]" 639 "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" 640 "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" 641 "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" 642 "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" 643 "($help)--pid=[PID namespace to use]:PID: " 644 "($help)--privileged[Give extended privileges to this container]" 645 "($help)--read-only[Mount the container's root filesystem as read only]" 646 "($help)*--security-opt=[Security options]:security option: " 647 "($help)*--sysctl=-[sysctl options]:sysctl: " 648 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" 649 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" 650 "($help)--tmpfs[mount tmpfs]" 651 "($help)*-v[Bind mount a volume]:volume: " 652 "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" 653 "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " 654 "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" 655 ) 656 opts_create_run_update=( 657 "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" 658 "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " 659 "($help)--memory-reservation=[Memory soft limit]:Memory limit: " 660 "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" 661 ) 662 opts_attach_exec_run_start=( 663 "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" 664 ) 665 666 case "$words[1]" in 667 (attach) 668 _arguments $(__docker_arguments) \ 669 $opts_help \ 670 $opts_attach_exec_run_start \ 671 "($help)--no-stdin[Do not attach stdin]" \ 672 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 673 "($help -):containers:__docker_runningcontainers" && ret=0 674 ;; 675 (build) 676 _arguments $(__docker_arguments) \ 677 $opts_help \ 678 $opts_build_create_run \ 679 $opts_build_create_run_update \ 680 "($help)*--build-arg[Build-time variables]:<varname>=<value>: " \ 681 "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ 682 "($help)--force-rm[Always remove intermediate containers]" \ 683 "($help)*--label=[Set metadata for an image]:label=value: " \ 684 "($help)--no-cache[Do not use cache when building the image]" \ 685 "($help)--pull[Attempt to pull a newer version of the image]" \ 686 "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ 687 "($help)--rm[Remove intermediate containers after a successful build]" \ 688 "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \ 689 "($help -):path or URL:_directories" && ret=0 690 ;; 691 (commit) 692 _arguments $(__docker_arguments) \ 693 $opts_help \ 694 "($help -a --author)"{-a=,--author=}"[Author]:author: " \ 695 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 696 "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ 697 "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ 698 "($help -):container:__docker_containers" \ 699 "($help -): :__docker_repositories_with_tags" && ret=0 700 ;; 701 (cp) 702 _arguments $(__docker_arguments) \ 703 $opts_help \ 704 "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ 705 "($help -)1:container:->container" \ 706 "($help -)2:hostpath:_files" && ret=0 707 case $state in 708 (container) 709 if compset -P "*:"; then 710 _files && ret=0 711 else 712 __docker_containers -qS ":" && ret=0 713 fi 714 ;; 715 esac 716 ;; 717 (create) 718 _arguments $(__docker_arguments) \ 719 $opts_help \ 720 $opts_build_create_run \ 721 $opts_build_create_run_update \ 722 $opts_create_run \ 723 $opts_create_run_update \ 724 "($help -): :__docker_images" \ 725 "($help -):command: _command_names -e" \ 726 "($help -)*::arguments: _normal" && ret=0 727 728 case $state in 729 (link) 730 if compset -P "*:"; then 731 _wanted alias expl "Alias" compadd -E "" && ret=0 732 else 733 __docker_runningcontainers -qS ":" && ret=0 734 fi 735 ;; 736 esac 737 738 ;; 739 (daemon) 740 _arguments $(__docker_arguments) \ 741 $opts_help \ 742 "($help)--api-cors-header=[CORS headers in the remote API]:CORS headers: " \ 743 "($help)*--authorization-plugin=[Authorization plugins to load]" \ 744 "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ 745 "($help)--bip=[Network bridge IP]:IP address: " \ 746 "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ 747 "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ 748 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 749 "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ 750 "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ 751 "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \ 752 "($help)--cluster-advertise=[Address of the daemon instance to advertise]:Instance to advertise (host\:port): " \ 753 "($help)*--cluster-store-opt=[Cluster options]:Cluster options:->cluster-store-options" \ 754 "($help)*--dns=[DNS server to use]:DNS: " \ 755 "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ 756 "($help)*--dns-opt=[DNS options to use]:DNS option: " \ 757 "($help)*--default-ulimit=[Default ulimit settings for containers]:ulimit: " \ 758 "($help)--disable-legacy-registry[Do not contact legacy registries]" \ 759 "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ 760 "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ 761 "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ 762 "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ 763 "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ 764 "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \ 765 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 766 "($help)--icc[Enable inter-container communication]" \ 767 "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ 768 "($help)--ip=[Default IP when binding container ports]" \ 769 "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ 770 "($help)--ip-masq[Enable IP masquerading]" \ 771 "($help)--iptables[Enable addition of iptables rules]" \ 772 "($help)--ipv6[Enable IPv6 networking]" \ 773 "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ 774 "($help)*--label=[Key=value labels]:label: " \ 775 "($help)--log-driver=[Default driver for container logs]:Logging driver:(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog)" \ 776 "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" \ 777 "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ 778 "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ 779 "($help)--raw-logs[Full timestamps without ANSI coloring]" \ 780 "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \ 781 "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \ 782 "($help)--selinux-enabled[Enable selinux support]" \ 783 "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ 784 "($help)--tls[Use TLS]" \ 785 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ 786 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ 787 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ 788 "($help)--tlsverify[Use TLS and verify the remote]" \ 789 "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ 790 "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0 791 792 case $state in 793 (cluster-store) 794 if compset -P '*://'; then 795 _message 'host:port' && ret=0 796 else 797 store=('consul' 'etcd' 'zk') 798 _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0 799 fi 800 ;; 801 (cluster-store-options) 802 if compset -P '*='; then 803 _files && ret=0 804 else 805 opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path') 806 _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0 807 fi 808 ;; 809 (users-groups) 810 if compset -P '*:'; then 811 _groups && ret=0 812 else 813 _describe -t userns-default "default Docker user management" '(default)' && ret=0 814 _users && ret=0 815 fi 816 ;; 817 esac 818 ;; 819 (diff) 820 _arguments $(__docker_arguments) \ 821 $opts_help \ 822 "($help -)*:containers:__docker_containers" && ret=0 823 ;; 824 (events) 825 _arguments $(__docker_arguments) \ 826 $opts_help \ 827 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 828 "($help)--since=[Events created since this timestamp]:timestamp: " \ 829 "($help)--until=[Events created until this timestamp]:timestamp: " && ret=0 830 ;; 831 (exec) 832 local state 833 _arguments $(__docker_arguments) \ 834 $opts_help \ 835 $opts_attach_exec_run_start \ 836 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 837 "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ 838 "($help)--privileged[Give extended Linux capabilities to the command]" \ 839 "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ 840 "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ 841 "($help -):containers:__docker_runningcontainers" \ 842 "($help -)*::command:->anycommand" && ret=0 843 844 case $state in 845 (anycommand) 846 shift 1 words 847 (( CURRENT-- )) 848 _normal && ret=0 849 ;; 850 esac 851 ;; 852 (export) 853 _arguments $(__docker_arguments) \ 854 $opts_help \ 855 "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ 856 "($help -)*:containers:__docker_containers" && ret=0 857 ;; 858 (history) 859 _arguments $(__docker_arguments) \ 860 $opts_help \ 861 "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ 862 "($help)--no-trunc[Do not truncate output]" \ 863 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 864 "($help -)*: :__docker_images" && ret=0 865 ;; 866 (images) 867 _arguments $(__docker_arguments) \ 868 $opts_help \ 869 "($help -a --all)"{-a,--all}"[Show all images]" \ 870 "($help)--digests[Show digests]" \ 871 "($help)*"{-f=,--filter=}"[Filter values]:filter: " \ 872 "($help)--format[Pretty-print containers using a Go template]:format: " \ 873 "($help)--no-trunc[Do not truncate output]" \ 874 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 875 "($help -): :__docker_repositories" && ret=0 876 ;; 877 (import) 878 _arguments $(__docker_arguments) \ 879 $opts_help \ 880 "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ 881 "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ 882 "($help -):URL:(- http:// file://)" \ 883 "($help -): :__docker_repositories_with_tags" && ret=0 884 ;; 885 (info|version) 886 _arguments $(__docker_arguments) \ 887 $opts_help && ret=0 888 ;; 889 (inspect) 890 local state 891 _arguments $(__docker_arguments) \ 892 $opts_help \ 893 "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ 894 "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ 895 "($help)--type=[Return JSON for specified type]:type:(image container)" \ 896 "($help -)*: :->values" && ret=0 897 898 case $state in 899 (values) 900 if [[ ${words[(r)--type=container]} == --type=container ]]; then 901 __docker_containers && ret=0 902 elif [[ ${words[(r)--type=image]} == --type=image ]]; then 903 __docker_images && ret=0 904 else 905 __docker_images && __docker_containers && ret=0 906 fi 907 ;; 908 esac 909 ;; 910 (kill) 911 _arguments $(__docker_arguments) \ 912 $opts_help \ 913 "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ 914 "($help -)*:containers:__docker_runningcontainers" && ret=0 915 ;; 916 (load) 917 _arguments $(__docker_arguments) \ 918 $opts_help \ 919 "($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))(-.)\"" \ 920 "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 921 ;; 922 (login) 923 _arguments $(__docker_arguments) \ 924 $opts_help \ 925 "($help -p --password)"{-p=,--password=}"[Password]:password: " \ 926 "($help -u --user)"{-u=,--user=}"[Username]:username: " \ 927 "($help -)1:server: " && ret=0 928 ;; 929 (logout) 930 _arguments $(__docker_arguments) \ 931 $opts_help \ 932 "($help -)1:server: " && ret=0 933 ;; 934 (logs) 935 _arguments $(__docker_arguments) \ 936 $opts_help \ 937 "($help -f --follow)"{-f,--follow}"[Follow log output]" \ 938 "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ 939 "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ 940 "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ 941 "($help -)*:containers:__docker_containers" && ret=0 942 ;; 943 (network) 944 local curcontext="$curcontext" state 945 _arguments $(__docker_arguments) \ 946 $opts_help \ 947 "($help -): :->command" \ 948 "($help -)*:: :->option-or-argument" && ret=0 949 950 case $state in 951 (command) 952 __docker_network_commands && ret=0 953 ;; 954 (option-or-argument) 955 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 956 __docker_network_subcommand && ret=0 957 ;; 958 esac 959 ;; 960 (pause|unpause) 961 _arguments $(__docker_arguments) \ 962 $opts_help \ 963 "($help -)*:containers:__docker_runningcontainers" && ret=0 964 ;; 965 (port) 966 _arguments $(__docker_arguments) \ 967 $opts_help \ 968 "($help -)1:containers:__docker_runningcontainers" \ 969 "($help -)2:port:_ports" && ret=0 970 ;; 971 (ps) 972 _arguments $(__docker_arguments) \ 973 $opts_help \ 974 "($help -a --all)"{-a,--all}"[Show all containers]" \ 975 "($help)--before=[Show only container created before...]:containers:__docker_containers" \ 976 "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ 977 "($help)--format[Pretty-print containers using a Go template]:format: " \ 978 "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ 979 "($help)-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)" \ 980 "($help)--no-trunc[Do not truncate output]" \ 981 "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ 982 "($help -s --size)"{-s,--size}"[Display total file sizes]" \ 983 "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0 984 985 case $state in 986 (filter-options) 987 __docker_complete_ps_filters && ret=0 988 ;; 989 esac 990 ;; 991 (pull) 992 _arguments $(__docker_arguments) \ 993 $opts_help \ 994 "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ 995 "($help)--disable-content-trust[Skip image verification]" \ 996 "($help -):name:__docker_search" && ret=0 997 ;; 998 (push) 999 _arguments $(__docker_arguments) \ 1000 $opts_help \ 1001 "($help)--disable-content-trust[Skip image signing]" \ 1002 "($help -): :__docker_images" && ret=0 1003 ;; 1004 (rename) 1005 _arguments $(__docker_arguments) \ 1006 $opts_help \ 1007 "($help -):old name:__docker_containers" \ 1008 "($help -):new name: " && ret=0 1009 ;; 1010 (restart|stop) 1011 _arguments $(__docker_arguments) \ 1012 $opts_help \ 1013 "($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)" \ 1014 "($help -)*:containers:__docker_runningcontainers" && ret=0 1015 ;; 1016 (rm) 1017 _arguments $(__docker_arguments) \ 1018 $opts_help \ 1019 "($help -f --force)"{-f,--force}"[Force removal]" \ 1020 "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ 1021 "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ 1022 "($help -)*:containers:__docker_stoppedcontainers" && ret=0 1023 ;; 1024 (rmi) 1025 _arguments $(__docker_arguments) \ 1026 $opts_help \ 1027 "($help -f --force)"{-f,--force}"[Force removal]" \ 1028 "($help)--no-prune[Do not delete untagged parents]" \ 1029 "($help -)*: :__docker_images" && ret=0 1030 ;; 1031 (run) 1032 _arguments $(__docker_arguments) \ 1033 $opts_help \ 1034 $opts_build_create_run \ 1035 $opts_build_create_run_update \ 1036 $opts_create_run \ 1037 $opts_create_run_update \ 1038 $opts_attach_exec_run_start \ 1039 "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ 1040 "($help)--rm[Remove intermediate containers when it exits]" \ 1041 "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ 1042 "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \ 1043 "($help -): :__docker_images" \ 1044 "($help -):command: _command_names -e" \ 1045 "($help -)*::arguments: _normal" && ret=0 1046 1047 case $state in 1048 (link) 1049 if compset -P "*:"; then 1050 _wanted alias expl "Alias" compadd -E "" && ret=0 1051 else 1052 __docker_runningcontainers -qS ":" && ret=0 1053 fi 1054 ;; 1055 esac 1056 1057 ;; 1058 (save) 1059 _arguments $(__docker_arguments) \ 1060 $opts_help \ 1061 "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ 1062 "($help -)*: :__docker_images" && ret=0 1063 ;; 1064 (search) 1065 _arguments $(__docker_arguments) \ 1066 $opts_help \ 1067 "($help)--automated[Only show automated builds]" \ 1068 "($help)--no-trunc[Do not truncate output]" \ 1069 "($help -s --stars)"{-s=,--stars=}"[Only display with at least X stars]:stars:(0 10 100 1000)" \ 1070 "($help -):term: " && ret=0 1071 ;; 1072 (start) 1073 _arguments $(__docker_arguments) \ 1074 $opts_help \ 1075 $opts_attach_exec_run_start \ 1076 "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ 1077 "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \ 1078 "($help -)*:containers:__docker_stoppedcontainers" && ret=0 1079 ;; 1080 (stats) 1081 _arguments $(__docker_arguments) \ 1082 $opts_help \ 1083 "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ 1084 "($help)--no-stream[Disable streaming stats and only pull the first result]" \ 1085 "($help -)*:containers:__docker_runningcontainers" && ret=0 1086 ;; 1087 (tag) 1088 _arguments $(__docker_arguments) \ 1089 $opts_help \ 1090 "($help -):source:__docker_images"\ 1091 "($help -):destination:__docker_repositories_with_tags" && ret=0 1092 ;; 1093 (top) 1094 _arguments $(__docker_arguments) \ 1095 $opts_help \ 1096 "($help -)1:containers:__docker_runningcontainers" \ 1097 "($help -)*:: :->ps-arguments" && ret=0 1098 case $state in 1099 (ps-arguments) 1100 _ps && ret=0 1101 ;; 1102 esac 1103 1104 ;; 1105 (update) 1106 _arguments $(__docker_arguments) \ 1107 $opts_help \ 1108 $opts_create_run_update \ 1109 $opts_build_create_run_update \ 1110 "($help -)*: :->values" && ret=0 1111 1112 case $state in 1113 (values) 1114 if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then 1115 __docker_stoppedcontainers && ret=0 1116 else 1117 __docker_containers && ret=0 1118 fi 1119 ;; 1120 esac 1121 ;; 1122 (volume) 1123 local curcontext="$curcontext" state 1124 _arguments $(__docker_arguments) \ 1125 $opts_help \ 1126 "($help -): :->command" \ 1127 "($help -)*:: :->option-or-argument" && ret=0 1128 1129 case $state in 1130 (command) 1131 __docker_volume_commands && ret=0 1132 ;; 1133 (option-or-argument) 1134 curcontext=${curcontext%:*:*}:docker-${words[-1]}: 1135 __docker_volume_subcommand && ret=0 1136 ;; 1137 esac 1138 ;; 1139 (wait) 1140 _arguments $(__docker_arguments) \ 1141 $opts_help \ 1142 "($help -)*:containers:__docker_runningcontainers" && ret=0 1143 ;; 1144 (help) 1145 _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 1146 ;; 1147 esac 1148 1149 return ret 1150 } 1151 1152 _docker() { 1153 # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. 1154 # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. 1155 if [[ $service != docker ]]; then 1156 _call_function - _$service 1157 return 1158 fi 1159 1160 local curcontext="$curcontext" state line help="-h --help" 1161 integer ret=1 1162 typeset -A opt_args 1163 1164 _arguments $(__docker_arguments) -C \ 1165 "(: -)"{-h,--help}"[Print usage]" \ 1166 "($help)--config[Location of client config files]:path:_directories" \ 1167 "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ 1168 "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ 1169 "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ 1170 "($help)--tls[Use TLS]" \ 1171 "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ 1172 "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ 1173 "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ 1174 "($help)--tlsverify[Use TLS and verify the remote]" \ 1175 "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ 1176 "($help -v --version)"{-v,--version}"[Print version information and quit]" \ 1177 "($help -): :->command" \ 1178 "($help -)*:: :->option-or-argument" && ret=0 1179 1180 local host=${opt_args[-H]}${opt_args[--host]} 1181 local config=${opt_args[--config]} 1182 local docker_options="${host:+--host $host} ${config:+--config $config}" 1183 1184 case $state in 1185 (command) 1186 __docker_commands && ret=0 1187 ;; 1188 (option-or-argument) 1189 curcontext=${curcontext%:*:*}:docker-$words[1]: 1190 __docker_subcommand && ret=0 1191 ;; 1192 esac 1193 1194 return ret 1195 } 1196 1197 _docker "$@" 1198 1199 # Local Variables: 1200 # mode: Shell-Script 1201 # sh-indentation: 4 1202 # indent-tabs-mode: nil 1203 # sh-basic-offset: 4 1204 # End: 1205 # vim: ft=zsh sw=4 ts=4 et