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