github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/contrib/completion/zsh/_docker (about)

     1  #compdef docker dockerd
     2  #
     3  # zsh completion for docker (http://docker.com)
     4  #
     5  # version:  0.3.0
     6  # github:   https://github.com/felixr/docker-zsh-completion
     7  #
     8  # contributors:
     9  #   - Felix Riedel
    10  #   - Steve Durrheimer
    11  #   - Vincent Bernat
    12  #
    13  # license:
    14  #
    15  # Copyright (c) 2013, Felix Riedel
    16  # All rights reserved.
    17  #
    18  # Redistribution and use in source and binary forms, with or without
    19  # modification, are permitted provided that the following conditions are met:
    20  #     * Redistributions of source code must retain the above copyright
    21  #       notice, this list of conditions and the following disclaimer.
    22  #     * Redistributions in binary form must reproduce the above copyright
    23  #       notice, this list of conditions and the following disclaimer in the
    24  #       documentation and/or other materials provided with the distribution.
    25  #     * Neither the name of the <organization> nor the
    26  #       names of its contributors may be used to endorse or promote products
    27  #       derived from this software without specific prior written permission.
    28  #
    29  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    30  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    31  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    32  # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
    33  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    34  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    35  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    36  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    37  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    38  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    39  #
    40  
    41  # Short-option stacking can be enabled with:
    42  #  zstyle ':completion:*:*:docker:*' option-stacking yes
    43  #  zstyle ':completion:*:*:docker-*:*' option-stacking yes
    44  __docker_arguments() {
    45      if zstyle -t ":completion:${curcontext}:" option-stacking; then
    46          print -- -s
    47      fi
    48  }
    49  
    50  __docker_get_containers() {
    51      [[ $PREFIX = -* ]] && return 1
    52      integer ret=1
    53      local kind type line s
    54      declare -a running stopped lines args names
    55  
    56      kind=$1; shift
    57      type=$1; shift
    58      [[ $kind = (stopped|all) ]] && args=($args -a)
    59  
    60      lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}})
    61  
    62      # Parse header line to find columns
    63      local i=1 j=1 k header=${lines[1]}
    64      declare -A begin end
    65      while (( j < ${#header} - 1 )); do
    66          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
    67          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
    68          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
    69          begin[${header[$i,$((j-1))]}]=$i
    70          end[${header[$i,$((j-1))]}]=$k
    71      done
    72      end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line
    73      lines=(${lines[2,-1]})
    74  
    75      # Container ID
    76      if [[ $type = (ids|all) ]]; then
    77          for line in $lines; do
    78              s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}"
    79              s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
    80              s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
    81              if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
    82                  stopped=($stopped $s)
    83              else
    84                  running=($running $s)
    85              fi
    86          done
    87      fi
    88  
    89      # Names: we only display the one without slash. All other names
    90      # are generated and may clutter the completion. However, with
    91      # Swarm, all names may be prefixed by the swarm node name.
    92      if [[ $type = (names|all) ]]; then
    93          for line in $lines; do
    94              names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}})
    95              # First step: find a common prefix and strip it (swarm node case)
    96              (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/}
    97              # Second step: only keep the first name without a /
    98              s=${${names:#*/*}[1]}
    99              # If no name, well give up.
   100              (( $#s != 0 )) || continue
   101              s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
   102              s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
   103              if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
   104                  stopped=($stopped $s)
   105              else
   106                  running=($running $s)
   107              fi
   108          done
   109      fi
   110  
   111      [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0
   112      [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0
   113      return ret
   114  }
   115  
   116  __docker_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_complete_info_plugins() {
   142      [[ $PREFIX = -* ]] && return 1
   143      integer ret=1
   144      emulate -L zsh
   145      setopt extendedglob
   146      local -a plugins
   147      plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: })
   148      _describe -t plugins "$1 plugins" plugins && ret=0
   149      return ret
   150  }
   151  
   152  __docker_images() {
   153      [[ $PREFIX = -* ]] && return 1
   154      integer ret=1
   155      declare -a images
   156      images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}})
   157      _describe -t docker-images "images" images && ret=0
   158      __docker_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)"$'\n'}}%% *}[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)"$'\n'}}[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)"$'\n'}}%% *}[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 logentries_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      logentries_options=("logentries-token")
   231      syslog_options=("env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag")
   232      splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag")
   233  
   234      [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0
   235      [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0
   236      [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0
   237      [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0
   238      [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0
   239      [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0
   240      [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0
   241      [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0
   242      [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0
   243  
   244      return ret
   245  }
   246  
   247  __docker_log_drivers() {
   248      [[ $PREFIX = -*  ]] && return 1
   249      integer ret=1
   250      drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog)
   251      _describe -t log-drivers "log drivers" drivers && ret=0
   252      return ret
   253  }
   254  
   255  __docker_log_options() {
   256      [[ $PREFIX = -* ]] && return 1
   257      integer ret=1
   258  
   259      if compset -P '*='; then
   260          case "${${words[-1]%=*}#*=}" in
   261              (syslog-format)
   262                  syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro')
   263                  _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0
   264                  ;;
   265              *)
   266                  _message 'value' && ret=0
   267                  ;;
   268          esac
   269      else
   270          __docker_get_log_options -qS "=" && ret=0
   271      fi
   272  
   273      return ret
   274  }
   275  
   276  __docker_complete_detach_keys() {
   277      [[ $PREFIX = -* ]] && return 1
   278      integer ret=1
   279  
   280      compset -P "*,"
   281      keys=(${:-{a-z}})
   282      ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}})
   283      _describe -t detach_keys "[a-z]" keys -qS "," && ret=0
   284      _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0
   285  }
   286  
   287  __docker_complete_pid() {
   288      [[ $PREFIX = -* ]] && return 1
   289      integer ret=1
   290      local -a opts vopts
   291  
   292      opts=('host')
   293      vopts=('container')
   294  
   295      if compset -P '*:'; then
   296          case "${${words[-1]%:*}#*=}" in
   297              (container)
   298                  __docker_runningcontainers && ret=0
   299                  ;;
   300              *)
   301                  _message 'value' && ret=0
   302                  ;;
   303          esac
   304      else
   305          _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0
   306          _describe -t pid-opts "PID Options" opts && ret=0
   307      fi
   308  
   309      return ret
   310  }
   311  
   312  __docker_complete_runtimes() {
   313      [[ $PREFIX = -*  ]] && return 1
   314      integer ret=1
   315  
   316      emulate -L zsh
   317      setopt extendedglob
   318      local -a runtimes_opts
   319      runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}})
   320      _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0
   321  }
   322  
   323  __docker_complete_ps_filters() {
   324      [[ $PREFIX = -* ]] && return 1
   325      integer ret=1
   326  
   327      if compset -P '*='; then
   328          case "${${words[-1]%=*}#*=}" in
   329              (ancestor)
   330                  __docker_images && ret=0
   331                  ;;
   332              (before|since)
   333                  __docker_containers && ret=0
   334                  ;;
   335              (id)
   336                  __docker_containers_ids && ret=0
   337                  ;;
   338              (is-task)
   339                  _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
   340                  ;;
   341              (name)
   342                  __docker_containers_names && ret=0
   343                  ;;
   344              (network)
   345                  __docker_networks && ret=0
   346                  ;;
   347              (status)
   348                  status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing')
   349                  _describe -t status-filter-opts "Status Filter Options" status_opts && ret=0
   350                  ;;
   351              (volume)
   352                  __docker_volumes && ret=0
   353                  ;;
   354              *)
   355                  _message 'value' && ret=0
   356                  ;;
   357          esac
   358      else
   359          opts=('ancestor' 'before' 'exited' 'id' 'label' 'name' 'network' 'since' 'status' 'volume')
   360          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
   361      fi
   362  
   363      return ret
   364  }
   365  
   366  __docker_complete_search_filters() {
   367      [[ $PREFIX = -* ]] && return 1
   368      integer ret=1
   369      declare -a boolean_opts opts
   370  
   371      boolean_opts=('true' 'false')
   372      opts=('is-automated' 'is-official' 'stars')
   373  
   374      if compset -P '*='; then
   375          case "${${words[-1]%=*}#*=}" in
   376              (is-automated|is-official)
   377                  _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
   378                  ;;
   379              *)
   380                  _message 'value' && ret=0
   381                  ;;
   382          esac
   383      else
   384          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
   385      fi
   386  
   387      return ret
   388  }
   389  
   390  __docker_complete_images_filters() {
   391      [[ $PREFIX = -* ]] && return 1
   392      integer ret=1
   393      declare -a boolean_opts opts
   394  
   395      boolean_opts=('true' 'false')
   396      opts=('before' 'dangling' 'label' 'since')
   397  
   398      if compset -P '*='; then
   399          case "${${words[-1]%=*}#*=}" in
   400              (before|since)
   401                  __docker_images && ret=0
   402                  ;;
   403              (dangling)
   404                  _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
   405                  ;;
   406              *)
   407                  _message 'value' && ret=0
   408                  ;;
   409          esac
   410      else
   411          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
   412      fi
   413  
   414      return ret
   415  }
   416  
   417  __docker_complete_events_filter() {
   418      [[ $PREFIX = -* ]] && return 1
   419      integer ret=1
   420      declare -a opts
   421  
   422      opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume')
   423  
   424      if compset -P '*='; then
   425          case "${${words[-1]%=*}#*=}" in
   426              (container)
   427                  __docker_containers && ret=0
   428                  ;;
   429              (daemon)
   430                  emulate -L zsh
   431                  setopt extendedglob
   432                  local -a daemon_opts
   433                  daemon_opts=(
   434                      ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}}
   435                      ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:}
   436                  )
   437                  _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0
   438                  ;;
   439              (event)
   440                  local -a event_opts
   441                  event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach'
   442                  'exec_start' 'export' 'health_status' 'import' 'kill' 'load'  'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start'
   443                  'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update')
   444                  _describe -t event-filter-opts "event filter options" event_opts && ret=0
   445                  ;;
   446              (image)
   447                  __docker_images && ret=0
   448                  ;;
   449              (network)
   450                  __docker_networks && ret=0
   451                  ;;
   452              (type)
   453                  local -a type_opts
   454                  type_opts=('container' 'daemon' 'image' 'network' 'volume')
   455                  _describe -t type-filter-opts "type filter options" type_opts && ret=0
   456                  ;;
   457              (volume)
   458                  __docker_volumes && ret=0
   459                  ;;
   460              *)
   461                  _message 'value' && ret=0
   462                  ;;
   463          esac
   464      else
   465          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
   466      fi
   467  
   468      return ret
   469  }
   470  
   471  # BO network
   472  
   473  __docker_network_complete_ls_filters() {
   474      [[ $PREFIX = -* ]] && return 1
   475      integer ret=1
   476  
   477      if compset -P '*='; then
   478          case "${${words[-1]%=*}#*=}" in
   479              (driver)
   480                  __docker_complete_info_plugins Network && ret=0
   481                  ;;
   482              (id)
   483                  __docker_networks_ids && ret=0
   484                  ;;
   485              (name)
   486                  __docker_networks_names && ret=0
   487                  ;;
   488              (type)
   489                  type_opts=('builtin' 'custom')
   490                  _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0
   491                  ;;
   492              *)
   493                  _message 'value' && ret=0
   494                  ;;
   495          esac
   496      else
   497          opts=('driver' 'id' 'label' 'name' 'type')
   498          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
   499      fi
   500  
   501      return ret
   502  }
   503  
   504  __docker_get_networks() {
   505      [[ $PREFIX = -* ]] && return 1
   506      integer ret=1
   507      local line s
   508      declare -a lines networks
   509  
   510      type=$1; shift
   511  
   512      lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}})
   513  
   514      # Parse header line to find columns
   515      local i=1 j=1 k header=${lines[1]}
   516      declare -A begin end
   517      while (( j < ${#header} - 1 )); do
   518          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
   519          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
   520          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
   521          begin[${header[$i,$((j-1))]}]=$i
   522          end[${header[$i,$((j-1))]}]=$k
   523      done
   524      end[${header[$i,$((j-1))]}]=-1
   525      lines=(${lines[2,-1]})
   526  
   527      # Network ID
   528      if [[ $type = (ids|all) ]]; then
   529          for line in $lines; do
   530              s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}"
   531              s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   532              networks=($networks $s)
   533          done
   534      fi
   535  
   536      # Names
   537      if [[ $type = (names|all) ]]; then
   538          for line in $lines; do
   539              s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
   540              s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   541              networks=($networks $s)
   542          done
   543      fi
   544  
   545      _describe -t networks-list "networks" networks "$@" && ret=0
   546      return ret
   547  }
   548  
   549  __docker_networks() {
   550      [[ $PREFIX = -* ]] && return 1
   551      __docker_get_networks all "$@"
   552  }
   553  
   554  __docker_networks_ids() {
   555      [[ $PREFIX = -* ]] && return 1
   556      __docker_get_networks ids "$@"
   557  }
   558  
   559  __docker_networks_names() {
   560      [[ $PREFIX = -* ]] && return 1
   561      __docker_get_networks names "$@"
   562  }
   563  
   564  __docker_network_commands() {
   565      local -a _docker_network_subcommands
   566      _docker_network_subcommands=(
   567          "connect:Connect a container to a network"
   568          "create:Creates a new network with a name specified by the user"
   569          "disconnect:Disconnects a container from a network"
   570          "inspect:Displays detailed information on a network"
   571          "ls:Lists all the networks created by the user"
   572          "rm:Deletes one or more networks"
   573      )
   574      _describe -t docker-network-commands "docker network command" _docker_network_subcommands
   575  }
   576  
   577  __docker_network_subcommand() {
   578      local -a _command_args opts_help
   579      local expl help="--help"
   580      integer ret=1
   581  
   582      opts_help=("(: -)--help[Print usage]")
   583  
   584      case "$words[1]" in
   585          (connect)
   586              _arguments $(__docker_arguments) \
   587                  $opts_help \
   588                  "($help)*--alias=[Add network-scoped alias for the container]:alias: " \
   589                  "($help)--ip=[Container IPv4 address]:IPv4: " \
   590                  "($help)--ip6=[Container IPv6 address]:IPv6: " \
   591                  "($help)*--link=[Add a link to another container]:link:->link" \
   592                  "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \
   593                  "($help -)1:network:__docker_networks" \
   594                  "($help -)2:containers:__docker_containers" && ret=0
   595  
   596              case $state in
   597                  (link)
   598                      if compset -P "*:"; then
   599                          _wanted alias expl "Alias" compadd -E "" && ret=0
   600                      else
   601                          __docker_runningcontainers -qS ":" && ret=0
   602                      fi
   603                      ;;
   604              esac
   605              ;;
   606          (create)
   607              _arguments $(__docker_arguments) -A '-*' \
   608                  $opts_help \
   609                  "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \
   610                  "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \
   611                  "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \
   612                  "($help)--internal[Restricts external access to the network]" \
   613                  "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \
   614                  "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \
   615                  "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \
   616                  "($help)--ipv6[Enable IPv6 networking]" \
   617                  "($help)*--label=[Set metadata on a network]:label=value: " \
   618                  "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \
   619                  "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \
   620                  "($help -)1:Network Name: " && ret=0
   621              ;;
   622          (disconnect)
   623              _arguments $(__docker_arguments) \
   624                  $opts_help \
   625                  "($help -)1:network:__docker_networks" \
   626                  "($help -)2:containers:__docker_containers" && ret=0
   627              ;;
   628          (inspect)
   629              _arguments $(__docker_arguments) \
   630                  $opts_help \
   631                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
   632                  "($help -)*:network:__docker_networks" && ret=0
   633              ;;
   634          (ls)
   635              _arguments $(__docker_arguments) \
   636                  $opts_help \
   637                  "($help)--no-trunc[Do not truncate the output]" \
   638                  "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
   639                  "($help)--format=[Pretty-print networks using a Go template]:template: " \
   640                  "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0
   641              case $state in
   642                  (filter-options)
   643                      __docker_network_complete_ls_filters && ret=0
   644                      ;;
   645              esac
   646              ;;
   647          (rm)
   648              _arguments $(__docker_arguments) \
   649                  $opts_help \
   650                  "($help -)*:network:__docker_networks" && ret=0
   651              ;;
   652          (help)
   653              _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
   654              ;;
   655      esac
   656  
   657      return ret
   658  }
   659  
   660  # EO network
   661  
   662  # BO node
   663  
   664  __docker_node_complete_ls_filters() {
   665      [[ $PREFIX = -* ]] && return 1
   666      integer ret=1
   667  
   668      if compset -P '*='; then
   669          case "${${words[-1]%=*}#*=}" in
   670              (id)
   671                  __docker_complete_nodes_ids && ret=0
   672                  ;;
   673              (membership)
   674                  membership_opts=('accepted' 'pending' 'rejected')
   675                  _describe -t membership-opts "membership options" membership_opts && ret=0
   676                  ;;
   677              (name)
   678                  __docker_complete_nodes_names && ret=0
   679                  ;;
   680              (role)
   681                  role_opts=('manager' 'worker')
   682                  _describe -t role-opts "role options" role_opts && ret=0
   683                  ;;
   684              *)
   685                  _message 'value' && ret=0
   686                  ;;
   687          esac
   688      else
   689          opts=('id' 'label' 'membership' 'name' 'role')
   690          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
   691      fi
   692  
   693      return ret
   694  }
   695  
   696  __docker_node_complete_ps_filters() {
   697      [[ $PREFIX = -* ]] && return 1
   698      integer ret=1
   699  
   700      if compset -P '*='; then
   701          case "${${words[-1]%=*}#*=}" in
   702              (desired-state)
   703                  state_opts=('accepted' 'running')
   704                  _describe -t state-opts "desired state options" state_opts && ret=0
   705                  ;;
   706              *)
   707                  _message 'value' && ret=0
   708                  ;;
   709          esac
   710      else
   711          opts=('desired-state' 'id' 'label' 'name')
   712          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
   713      fi
   714  
   715      return ret
   716  }
   717  
   718  __docker_nodes() {
   719      [[ $PREFIX = -* ]] && return 1
   720      integer ret=1
   721      local line s
   722      declare -a lines nodes args
   723  
   724      type=$1; shift
   725      filter=$1; shift
   726      [[ $filter != "none" ]] && args=("-f $filter")
   727  
   728      lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}})
   729      # Parse header line to find columns
   730      local i=1 j=1 k header=${lines[1]}
   731      declare -A begin end
   732      while (( j < ${#header} - 1 )); do
   733          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
   734          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
   735          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
   736          begin[${header[$i,$((j-1))]}]=$i
   737          end[${header[$i,$((j-1))]}]=$k
   738      done
   739      end[${header[$i,$((j-1))]}]=-1
   740      lines=(${lines[2,-1]})
   741  
   742      # Node ID
   743      if [[ $type = (ids|all) ]]; then
   744          for line in $lines; do
   745              s="${line[${begin[ID]},${end[ID]}]%% ##}"
   746              nodes=($nodes $s)
   747          done
   748      fi
   749  
   750      # Names
   751      if [[ $type = (names|all) ]]; then
   752          for line in $lines; do
   753              s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
   754              nodes=($nodes $s)
   755          done
   756      fi
   757  
   758      _describe -t nodes-list "nodes" nodes "$@" && ret=0
   759      return ret
   760  }
   761  
   762  __docker_complete_nodes() {
   763      [[ $PREFIX = -* ]] && return 1
   764      __docker_nodes all none "$@"
   765  }
   766  
   767  __docker_complete_nodes_ids() {
   768      [[ $PREFIX = -* ]] && return 1
   769      __docker_nodes ids none "$@"
   770  }
   771  
   772  __docker_complete_nodes_names() {
   773      [[ $PREFIX = -* ]] && return 1
   774      __docker_nodes names none "$@"
   775  }
   776  
   777  __docker_complete_pending_nodes() {
   778      [[ $PREFIX = -* ]] && return 1
   779      __docker_nodes all "membership=pending" "$@"
   780  }
   781  
   782  __docker_complete_manager_nodes() {
   783      [[ $PREFIX = -* ]] && return 1
   784      __docker_nodes all "role=manager" "$@"
   785  }
   786  
   787  __docker_complete_worker_nodes() {
   788      [[ $PREFIX = -* ]] && return 1
   789      __docker_nodes all "role=worker" "$@"
   790  }
   791  
   792  __docker_node_commands() {
   793      local -a _docker_node_subcommands
   794      _docker_node_subcommands=(
   795          "demote:Demote a node as manager in the swarm"
   796          "inspect:Display detailed information on one or more nodes"
   797          "ls:List nodes in the swarm"
   798          "promote:Promote a node as manager in the swarm"
   799          "rm:Remove one or more nodes from the swarm"
   800          "ps:List tasks running on one or more nodes, defaults to current node"
   801          "update:Update a node"
   802      )
   803      _describe -t docker-node-commands "docker node command" _docker_node_subcommands
   804  }
   805  
   806  __docker_node_subcommand() {
   807      local -a _command_args opts_help
   808      local expl help="--help"
   809      integer ret=1
   810  
   811      opts_help=("(: -)--help[Print usage]")
   812  
   813      case "$words[1]" in
   814          (rm|remove)
   815               _arguments $(__docker_arguments) \
   816                  $opts_help \
   817                  "($help)--force[Force remove an active node]" \
   818                  "($help -)*:node:__docker_complete_pending_nodes" && ret=0
   819              ;;
   820          (demote)
   821               _arguments $(__docker_arguments) \
   822                  $opts_help \
   823                  "($help -)*:node:__docker_complete_manager_nodes" && ret=0
   824              ;;
   825          (inspect)
   826              _arguments $(__docker_arguments) \
   827                  $opts_help \
   828                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
   829                  "($help)--pretty[Print the information in a human friendly format]" \
   830                  "($help -)*:node:__docker_complete_nodes" && ret=0
   831              ;;
   832          (ls|list)
   833              _arguments $(__docker_arguments) \
   834                  $opts_help \
   835                  "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
   836                  "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0
   837              case $state in
   838                  (filter-options)
   839                      __docker_node_complete_ls_filters && ret=0
   840                      ;;
   841              esac
   842              ;;
   843          (promote)
   844               _arguments $(__docker_arguments) \
   845                  $opts_help \
   846                  "($help -)*:node:__docker_complete_worker_nodes" && ret=0
   847              ;;
   848          (ps)
   849              _arguments $(__docker_arguments) \
   850                  $opts_help \
   851                  "($help -a --all)"{-a,--all}"[Display all instances]" \
   852                  "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
   853                  "($help)--no-resolve[Do not map IDs to Names]" \
   854                  "($help)--no-trunc[Do not truncate output]" \
   855                  "($help -)*:node:__docker_complete_nodes" && ret=0
   856              case $state in
   857                  (filter-options)
   858                      __docker_node_complete_ps_filters && ret=0
   859                      ;;
   860              esac
   861              ;;
   862          (update)
   863              _arguments $(__docker_arguments) \
   864                  $opts_help \
   865                  "($help)--availability=[Availability of the node]:availability:(active pause drain)" \
   866                  "($help)*--label-add=[Add or update a node label]:key=value: " \
   867                  "($help)*--label-rm=[Remove a node label if exists]:label: " \
   868                  "($help)--role=[Role of the node]:role:(manager worker)" \
   869                  "($help -)1:node:__docker_complete_nodes" && ret=0
   870              ;;
   871          (help)
   872              _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0
   873              ;;
   874      esac
   875  
   876      return ret
   877  }
   878  
   879  # EO node
   880  
   881  # BO plugin
   882  
   883  __docker_complete_plugins() {
   884      [[ $PREFIX = -* ]] && return 1
   885      integer ret=1
   886      local line s
   887      declare -a lines plugins
   888  
   889      lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls)"$'\n'}})
   890  
   891      # Parse header line to find columns
   892      local i=1 j=1 k header=${lines[1]}
   893      declare -A begin end
   894      while (( j < ${#header} - 1 )); do
   895          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
   896          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
   897          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
   898          begin[${header[$i,$((j-1))]}]=$i
   899          end[${header[$i,$((j-1))]}]=$k
   900      done
   901      end[${header[$i,$((j-1))]}]=-1
   902      lines=(${lines[2,-1]})
   903  
   904      # Name
   905      for line in $lines; do
   906          s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
   907          s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}"
   908          plugins=($plugins $s)
   909      done
   910  
   911      _describe -t plugins-list "plugins" plugins "$@" && ret=0
   912      return ret
   913  }
   914  
   915  __docker_plugin_commands() {
   916      local -a _docker_plugin_subcommands
   917      _docker_plugin_subcommands=(
   918          "disable:Disable a plugin"
   919          "enable:Enable a plugin"
   920          "inspect:Return low-level information about a plugin"
   921          "install:Install a plugin"
   922          "ls:List plugins"
   923          "push:Push a plugin"
   924          "rm:Remove a plugin"
   925          "set:Change settings for a plugin"
   926      )
   927      _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands
   928  }
   929  
   930  __docker_plugin_subcommand() {
   931      local -a _command_args opts_help
   932      local expl help="--help"
   933      integer ret=1
   934  
   935      opts_help=("(: -)--help[Print usage]")
   936  
   937      case "$words[1]" in
   938          (disable|enable|inspect|install|ls|push|rm)
   939              _arguments $(__docker_arguments) \
   940                  $opts_help \
   941                  "($help -)1:plugin:__docker_complete_plugins" && ret=0
   942              ;;
   943          (set)
   944              _arguments $(__docker_arguments) \
   945                  $opts_help \
   946                  "($help -)1:plugin:__docker_complete_plugins" \
   947                  "($help-)*:key=value: " && ret=0
   948              ;;
   949          (help)
   950              _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0
   951              ;;
   952      esac
   953  
   954      return ret
   955  }
   956  
   957  # EO plugin
   958  
   959  # BO service
   960  
   961  __docker_service_complete_ls_filters() {
   962      [[ $PREFIX = -* ]] && return 1
   963      integer ret=1
   964  
   965      if compset -P '*='; then
   966          case "${${words[-1]%=*}#*=}" in
   967              (id)
   968                  __docker_complete_services_ids && ret=0
   969                  ;;
   970              (name)
   971                  __docker_complete_services_names && ret=0
   972                  ;;
   973              *)
   974                  _message 'value' && ret=0
   975                  ;;
   976          esac
   977      else
   978          opts=('id' 'label' 'name')
   979          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
   980      fi
   981  
   982      return ret
   983  }
   984  
   985  __docker_service_complete_ps_filters() {
   986      [[ $PREFIX = -* ]] && return 1
   987      integer ret=1
   988  
   989      if compset -P '*='; then
   990          case "${${words[-1]%=*}#*=}" in
   991              (desired-state)
   992                  state_opts=('accepted' 'running')
   993                  _describe -t state-opts "desired state options" state_opts && ret=0
   994                  ;;
   995              *)
   996                  _message 'value' && ret=0
   997                  ;;
   998          esac
   999      else
  1000          opts=('desired-state' 'id' 'label' 'name')
  1001          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  1002      fi
  1003  
  1004      return ret
  1005  }
  1006  
  1007  __docker_services() {
  1008      [[ $PREFIX = -* ]] && return 1
  1009      integer ret=1
  1010      local line s
  1011      declare -a lines services
  1012  
  1013      type=$1; shift
  1014  
  1015      lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}})
  1016  
  1017      # Parse header line to find columns
  1018      local i=1 j=1 k header=${lines[1]}
  1019      declare -A begin end
  1020      while (( j < ${#header} - 1 )); do
  1021          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  1022          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
  1023          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  1024          begin[${header[$i,$((j-1))]}]=$i
  1025          end[${header[$i,$((j-1))]}]=$k
  1026      done
  1027      end[${header[$i,$((j-1))]}]=-1
  1028      lines=(${lines[2,-1]})
  1029  
  1030      # Service ID
  1031      if [[ $type = (ids|all) ]]; then
  1032          for line in $lines; do
  1033              s="${line[${begin[ID]},${end[ID]}]%% ##}"
  1034              s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}"
  1035              services=($services $s)
  1036          done
  1037      fi
  1038  
  1039      # Names
  1040      if [[ $type = (names|all) ]]; then
  1041          for line in $lines; do
  1042              s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  1043              s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}"
  1044              services=($services $s)
  1045          done
  1046      fi
  1047  
  1048      _describe -t services-list "services" services "$@" && ret=0
  1049      return ret
  1050  }
  1051  
  1052  __docker_complete_services() {
  1053      [[ $PREFIX = -* ]] && return 1
  1054      __docker_services all "$@"
  1055  }
  1056  
  1057  __docker_complete_services_ids() {
  1058      [[ $PREFIX = -* ]] && return 1
  1059      __docker_services ids "$@"
  1060  }
  1061  
  1062  __docker_complete_services_names() {
  1063      [[ $PREFIX = -* ]] && return 1
  1064      __docker_services names "$@"
  1065  }
  1066  
  1067  __docker_service_commands() {
  1068      local -a _docker_service_subcommands
  1069      _docker_service_subcommands=(
  1070          "create:Create a new service"
  1071          "inspect:Display detailed information on one or more services"
  1072          "ls:List services"
  1073          "rm:Remove one or more services"
  1074          "scale:Scale one or multiple services"
  1075          "ps:List the tasks of a service"
  1076          "update:Update a service"
  1077      )
  1078      _describe -t docker-service-commands "docker service command" _docker_service_subcommands
  1079  }
  1080  
  1081  __docker_service_subcommand() {
  1082      local -a _command_args opts_help opts_create_update
  1083      local expl help="--help"
  1084      integer ret=1
  1085  
  1086      opts_help=("(: -)--help[Print usage]")
  1087      opts_create_update=(
  1088          "($help)*--constraint=[Placement constraints]:constraint: "
  1089          "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)"
  1090          "($help)*"{-e=,--env=}"[Set environment variables]:env: "
  1091          "($help)*--group-add=[Add additional user groups to the container]:group:_groups"
  1092          "($help)*--label=[Service labels]:label: "
  1093          "($help)--limit-cpu=[Limit CPUs]:value: "
  1094          "($help)--limit-memory=[Limit Memory]:value: "
  1095          "($help)--log-driver=[Logging driver for service]:logging driver:__docker_log_drivers"
  1096          "($help)*--log-opt=[Logging driver options]:log driver options:__docker_log_options"
  1097          "($help)*--mount=[Attach a mount to the service]:mount: "
  1098          "($help)--name=[Service name]:name: "
  1099          "($help)*--network=[Network attachments]:network: "
  1100          "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: "
  1101          "($help)--replicas=[Number of tasks]:replicas: "
  1102          "($help)--reserve-cpu=[Reserve CPUs]:value: "
  1103          "($help)--reserve-memory=[Reserve Memory]:value: "
  1104          "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)"
  1105          "($help)--restart-delay=[Delay between restart attempts]:delay: "
  1106          "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: "
  1107          "($help)--restart-window=[Window used to evaluate the restart policy]:window: "
  1108          "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: "
  1109          "($help)--update-delay=[Delay between updates]:delay: "
  1110          "($help)--update-failure-action=[Action on update failure]:mode:(pause continue)"
  1111          "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: "
  1112          "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: "
  1113          "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: "
  1114          "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
  1115          "($help)--with-registry-auth[Send registry authentication details to swarm agents]"
  1116          "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
  1117      )
  1118  
  1119      case "$words[1]" in
  1120          (create)
  1121              _arguments $(__docker_arguments) \
  1122                  $opts_help \
  1123                  $opts_create_update \
  1124                  "($help)*--container-label=[Container labels]:label: " \
  1125                  "($help)--mode=[Service Mode]:mode:(global replicated)" \
  1126                  "($help -): :__docker_images" \
  1127                  "($help -):command: _command_names -e" \
  1128                  "($help -)*::arguments: _normal" && ret=0
  1129              ;;
  1130          (inspect)
  1131              _arguments $(__docker_arguments) \
  1132                  $opts_help \
  1133                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1134                  "($help)--pretty[Print the information in a human friendly format]" \
  1135                  "($help -)*:service:__docker_complete_services" && ret=0
  1136              ;;
  1137          (ls|list)
  1138              _arguments $(__docker_arguments) \
  1139                  $opts_help \
  1140                  "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:->filter-options" \
  1141                  "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0
  1142              case $state in
  1143                  (filter-options)
  1144                      __docker_service_complete_ls_filters && ret=0
  1145                      ;;
  1146              esac
  1147              ;;
  1148          (rm|remove)
  1149              _arguments $(__docker_arguments) \
  1150                  $opts_help \
  1151                  "($help -)*:service:__docker_complete_services" && ret=0
  1152              ;;
  1153          (scale)
  1154              _arguments $(__docker_arguments) \
  1155                  $opts_help \
  1156                  "($help -)*:service:->values" && ret=0
  1157              case $state in
  1158                  (values)
  1159                      if compset -P '*='; then
  1160                          _message 'replicas' && ret=0
  1161                      else
  1162                          __docker_complete_services -qS "="
  1163                      fi
  1164                      ;;
  1165              esac
  1166              ;;
  1167          (ps)
  1168              _arguments $(__docker_arguments) \
  1169                  $opts_help \
  1170                  "($help -a --all)"{-a,--all}"[Display all tasks]" \
  1171                  "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  1172                  "($help)--no-resolve[Do not map IDs to Names]" \
  1173                  "($help)--no-trunc[Do not truncate output]" \
  1174                  "($help -)1:service:__docker_complete_services" && ret=0
  1175              case $state in
  1176                  (filter-options)
  1177                      __docker_service_complete_ps_filters && ret=0
  1178                      ;;
  1179              esac
  1180              ;;
  1181          (update)
  1182              _arguments $(__docker_arguments) \
  1183                  $opts_help \
  1184                  $opts_create_update \
  1185                  "($help)--arg=[Service command args]:arguments: _normal" \
  1186                  "($help)*--container-label-add=[Add or update container labels]:label: " \
  1187                  "($help)*--container-label-rm=[Remove a container label by its key]:label: " \
  1188                  "($help)--force[Force update]" \
  1189                  "($help)*--group-rm=[Remove previously added user groups from the container]:group:_groups" \
  1190                  "($help)--image=[Service image tag]:image:__docker_repositories" \
  1191                  "($help)--rollback[Rollback to previous specification]" \
  1192                  "($help -)1:service:__docker_complete_services" && ret=0
  1193              ;;
  1194          (help)
  1195              _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0
  1196              ;;
  1197      esac
  1198  
  1199      return ret
  1200  }
  1201  
  1202  # EO service
  1203  
  1204  # BO swarm
  1205  
  1206  __docker_swarm_commands() {
  1207      local -a _docker_swarm_subcommands
  1208      _docker_swarm_subcommands=(
  1209          "init:Initialize a swarm"
  1210          "join:Join a swarm as a node and/or manager"
  1211          "join-token:Manage join tokens"
  1212          "leave:Leave a swarm"
  1213          "update:Update the swarm"
  1214      )
  1215      _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands
  1216  }
  1217  
  1218  __docker_swarm_subcommand() {
  1219      local -a _command_args opts_help
  1220      local expl help="--help"
  1221      integer ret=1
  1222  
  1223      opts_help=("(: -)--help[Print usage]")
  1224  
  1225      case "$words[1]" in
  1226          (init)
  1227              _arguments $(__docker_arguments) \
  1228                  $opts_help \
  1229                  "($help)--advertise-addr[Advertised address]:ip\:port: " \
  1230                  "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \
  1231                  "($help)--force-new-cluster[Force create a new cluster from current state]" \
  1232                  "($help)--listen-addr=[Listen address]:ip\:port: " && ret=0
  1233              ;;
  1234          (join)
  1235              _arguments $(__docker_arguments) \
  1236                  $opts_help \
  1237                  "($help)--advertise-addr[Advertised address]:ip\:port: " \
  1238                  "($help)--listen-addr=[Listen address]:ip\:port: " \
  1239                  "($help)--token=[Token for entry into the swarm]:secret: " \
  1240                  "($help -):host\:port: " && ret=0
  1241              ;;
  1242          (join-token)
  1243              _arguments $(__docker_arguments) \
  1244                  $opts_help \
  1245                  "($help -q --quiet)"{-q,--quiet}"[Only display token]" \
  1246                  "($help)--rotate[Rotate join token]" \
  1247                  "($help -):role:(manager worker)" && ret=0
  1248              ;;
  1249          (leave)
  1250              _arguments $(__docker_arguments) \
  1251                  $opts_help && ret=0
  1252              ;;
  1253          (update)
  1254              _arguments $(__docker_arguments) \
  1255                  $opts_help \
  1256                  "($help)--cert-expiry=[Validity period for node certificates]:duration: " \
  1257                  "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \
  1258                  "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0
  1259              ;;
  1260          (help)
  1261              _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
  1262              ;;
  1263      esac
  1264  
  1265      return ret
  1266  }
  1267  
  1268  # EO swarm
  1269  
  1270  # BO volume
  1271  
  1272  __docker_volume_complete_ls_filters() {
  1273      [[ $PREFIX = -* ]] && return 1
  1274      integer ret=1
  1275  
  1276      if compset -P '*='; then
  1277          case "${${words[-1]%=*}#*=}" in
  1278              (dangling)
  1279                  dangling_opts=('true' 'false')
  1280                  _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0
  1281                  ;;
  1282              (driver)
  1283                  __docker_complete_info_plugins Volume && ret=0
  1284                  ;;
  1285              (name)
  1286                  __docker_volumes && ret=0
  1287                  ;;
  1288              *)
  1289                  _message 'value' && ret=0
  1290                  ;;
  1291          esac
  1292      else
  1293          opts=('dangling' 'driver' 'label' 'name')
  1294          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  1295      fi
  1296  
  1297      return ret
  1298  }
  1299  
  1300  __docker_volumes() {
  1301      [[ $PREFIX = -* ]] && return 1
  1302      integer ret=1
  1303      declare -a lines volumes
  1304  
  1305      lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}})
  1306  
  1307      # Parse header line to find columns
  1308      local i=1 j=1 k header=${lines[1]}
  1309      declare -A begin end
  1310      while (( j < ${#header} - 1 )); do
  1311          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  1312          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
  1313          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  1314          begin[${header[$i,$((j-1))]}]=$i
  1315          end[${header[$i,$((j-1))]}]=$k
  1316      done
  1317      end[${header[$i,$((j-1))]}]=-1
  1318      lines=(${lines[2,-1]})
  1319  
  1320      # Names
  1321      local line s
  1322      for line in $lines; do
  1323          s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}"
  1324          s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
  1325          volumes=($volumes $s)
  1326      done
  1327  
  1328      _describe -t volumes-list "volumes" volumes && ret=0
  1329      return ret
  1330  }
  1331  
  1332  __docker_volume_commands() {
  1333      local -a _docker_volume_subcommands
  1334      _docker_volume_subcommands=(
  1335          "create:Create a volume"
  1336          "inspect:Display detailed information on one or more volumes"
  1337          "ls:List volumes"
  1338          "rm:Remove one or more volumes"
  1339      )
  1340      _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands
  1341  }
  1342  
  1343  __docker_volume_subcommand() {
  1344      local -a _command_args opts_help
  1345      local expl help="--help"
  1346      integer ret=1
  1347  
  1348      opts_help=("(: -)--help[Print usage]")
  1349  
  1350      case "$words[1]" in
  1351          (create)
  1352              _arguments $(__docker_arguments) -A '-*' \
  1353                  $opts_help \
  1354                  "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \
  1355                  "($help)*--label=[Set metadata for a volume]:label=value: " \
  1356                  "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \
  1357                  "($help -)1:Volume name: " && ret=0
  1358              ;;
  1359          (inspect)
  1360              _arguments $(__docker_arguments) \
  1361                  $opts_help \
  1362                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1363                  "($help -)1:volume:__docker_volumes" && ret=0
  1364              ;;
  1365          (ls)
  1366              _arguments $(__docker_arguments) \
  1367                  $opts_help \
  1368                  "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  1369                  "($help)--format=[Pretty-print volumes using a Go template]:template: " \
  1370                  "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0
  1371              case $state in
  1372                  (filter-options)
  1373                      __docker_volume_complete_ls_filters && ret=0
  1374                      ;;
  1375              esac
  1376              ;;
  1377          (rm)
  1378              _arguments $(__docker_arguments) \
  1379                  $opts_help \
  1380                  "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \
  1381                  "($help -):volume:__docker_volumes" && ret=0
  1382              ;;
  1383          (help)
  1384              _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0
  1385              ;;
  1386      esac
  1387  
  1388      return ret
  1389  }
  1390  
  1391  # EO volume
  1392  
  1393  __docker_caching_policy() {
  1394    oldp=( "$1"(Nmh+1) )     # 1 hour
  1395    (( $#oldp ))
  1396  }
  1397  
  1398  __docker_commands() {
  1399      local cache_policy
  1400  
  1401      zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  1402      if [[ -z "$cache_policy" ]]; then
  1403          zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
  1404      fi
  1405  
  1406      if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \
  1407          && ! _retrieve_cache docker_subcommands;
  1408      then
  1409          local -a lines
  1410          lines=(${(f)"$(_call_program commands docker 2>&1)"})
  1411          _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I)    *]}]}## #}/ ##/:})
  1412          _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command')
  1413          (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands
  1414      fi
  1415      _describe -t docker-commands "docker command" _docker_subcommands
  1416  }
  1417  
  1418  __docker_subcommand() {
  1419      local -a _command_args opts_help opts_build_create_run opts_build_create_run_update opts_create_run opts_create_run_update
  1420      local expl help="--help"
  1421      integer ret=1
  1422  
  1423      opts_help=("(: -)--help[Print usage]")
  1424      opts_build_create_run=(
  1425          "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: "
  1426          "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)"
  1427          "($help)--disable-content-trust[Skip image verification]"
  1428          "($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: "
  1429          "($help)*--ulimit=[ulimit options]:ulimit: "
  1430          "($help)--userns=[Container user namespace]:user namespace:(host)"
  1431      )
  1432      opts_build_create_run_update=(
  1433          "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)"
  1434          "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: "
  1435          "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: "
  1436          "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: "
  1437          "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: "
  1438          "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: "
  1439          "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: "
  1440          "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: "
  1441          "($help)--memory-swap=[Total memory limit with swap]:Memory limit: "
  1442      )
  1443      opts_create_run=(
  1444          "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
  1445          "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: "
  1446          "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: "
  1447          "($help)*--cap-add=[Add Linux capabilities]:capability: "
  1448          "($help)*--cap-drop=[Drop Linux capabilities]:capability: "
  1449          "($help)--cidfile=[Write the container ID to the file]:CID file:_files"
  1450          "($help)*--device=[Add a host device to the container]:device:_files"
  1451          "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: "
  1452          "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: "
  1453          "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: "
  1454          "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: "
  1455          "($help)*--dns=[Custom DNS servers]:DNS server: "
  1456          "($help)*--dns-opt=[Custom DNS options]:DNS option: "
  1457          "($help)*--dns-search=[Custom DNS search domains]:DNS domains: "
  1458          "($help)*"{-e=,--env=}"[Environment variables]:environment variable: "
  1459          "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: "
  1460          "($help)*--env-file=[Read environment variables from a file]:environment file:_files"
  1461          "($help)*--expose=[Expose a port from the container without publishing it]: "
  1462          "($help)*--group-add=[Add additional groups to run as]:group:_groups"
  1463          "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts"
  1464          "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]"
  1465          "($help)--ip=[Container IPv4 address]:IPv4: "
  1466          "($help)--ip6=[Container IPv6 address]:IPv6: "
  1467          "($help)--ipc=[IPC namespace to use]:IPC namespace: "
  1468          "($help)*--link=[Add link to another container]:link:->link"
  1469          "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: "
  1470          "($help)*"{-l=,--label=}"[Container metadata]:label: "
  1471          "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers"
  1472          "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options"
  1473          "($help)--mac-address=[Container MAC address]:MAC address: "
  1474          "($help)--name=[Container name]:name: "
  1475          "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)"
  1476          "($help)*--network-alias=[Add network-scoped alias for the container]:alias: "
  1477          "($help)--oom-kill-disable[Disable OOM Killer]"
  1478          "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]"
  1479          "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]"
  1480          "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
  1481          "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports"
  1482          "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid"
  1483          "($help)--privileged[Give extended privileges to this container]"
  1484          "($help)--read-only[Mount the container's root filesystem as read only]"
  1485          "($help)*--security-opt=[Security options]:security option: "
  1486          "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: "
  1487          "($help)*--sysctl=-[sysctl options]:sysctl: "
  1488          "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]"
  1489          "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
  1490          "($help)--tmpfs[mount tmpfs]"
  1491          "($help)*-v[Bind mount a volume]:volume: "
  1492          "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)"
  1493          "($help)*--volumes-from=[Mount volumes from the specified container]:volume: "
  1494          "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
  1495      )
  1496      opts_create_run_update=(
  1497          "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)"
  1498          "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: "
  1499          "($help)--memory-reservation=[Memory soft limit]:Memory limit: "
  1500          "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)"
  1501      )
  1502      opts_attach_exec_run_start=(
  1503          "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys"
  1504      )
  1505  
  1506      case "$words[1]" in
  1507          (attach)
  1508              _arguments $(__docker_arguments) \
  1509                  $opts_help \
  1510                  $opts_attach_exec_run_start \
  1511                  "($help)--no-stdin[Do not attach stdin]" \
  1512                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
  1513                  "($help -):containers:__docker_runningcontainers" && ret=0
  1514              ;;
  1515          (build)
  1516              _arguments $(__docker_arguments) \
  1517                  $opts_help \
  1518                  $opts_build_create_run \
  1519                  $opts_build_create_run_update \
  1520                  "($help)*--build-arg[Build-time variables]:<varname>=<value>: " \
  1521                  "($help)--compress[Compress the build context using gzip]" \
  1522                  "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \
  1523                  "($help)--force-rm[Always remove intermediate containers]" \
  1524                  "($help)*--label=[Set metadata for an image]:label=value: " \
  1525                  "($help)--no-cache[Do not use cache when building the image]" \
  1526                  "($help)--pull[Attempt to pull a newer version of the image]" \
  1527                  "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \
  1528                  "($help)--rm[Remove intermediate containers after a successful build]" \
  1529                  "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \
  1530                  "($help -):path or URL:_directories" && ret=0
  1531              ;;
  1532          (commit)
  1533              _arguments $(__docker_arguments) \
  1534                  $opts_help \
  1535                  "($help -a --author)"{-a=,--author=}"[Author]:author: " \
  1536                  "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
  1537                  "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \
  1538                  "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \
  1539                  "($help -):container:__docker_containers" \
  1540                  "($help -): :__docker_repositories_with_tags" && ret=0
  1541              ;;
  1542          (cp)
  1543              _arguments $(__docker_arguments) \
  1544                  $opts_help \
  1545                  "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \
  1546                  "($help -)1:container:->container" \
  1547                  "($help -)2:hostpath:_files" && ret=0
  1548              case $state in
  1549                  (container)
  1550                      if compset -P "*:"; then
  1551                          _files && ret=0
  1552                      else
  1553                          __docker_containers -qS ":" && ret=0
  1554                      fi
  1555                      ;;
  1556              esac
  1557              ;;
  1558          (create)
  1559              _arguments $(__docker_arguments) \
  1560                  $opts_help \
  1561                  $opts_build_create_run \
  1562                  $opts_build_create_run_update \
  1563                  $opts_create_run \
  1564                  $opts_create_run_update \
  1565                  "($help -): :__docker_images" \
  1566                  "($help -):command: _command_names -e" \
  1567                  "($help -)*::arguments: _normal" && ret=0
  1568  
  1569              case $state in
  1570                  (link)
  1571                      if compset -P "*:"; then
  1572                          _wanted alias expl "Alias" compadd -E "" && ret=0
  1573                      else
  1574                          __docker_runningcontainers -qS ":" && ret=0
  1575                      fi
  1576                      ;;
  1577              esac
  1578  
  1579              ;;
  1580          (daemon)
  1581              _arguments $(__docker_arguments) \
  1582                  $opts_help \
  1583                  "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \
  1584                  "($help)--api-cors-header=[CORS headers in the remote API]:CORS headers: " \
  1585                  "($help)*--authorization-plugin=[Authorization plugins to load]" \
  1586                  "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \
  1587                  "($help)--bip=[Network bridge IP]:IP address: " \
  1588                  "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \
  1589                  "($help)--cluster-advertise=[Address or interface name to advertise]:Instance to advertise (host\:port): " \
  1590                  "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \
  1591                  "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \
  1592                  "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \
  1593                  "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \
  1594                  "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
  1595                  "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \
  1596                  "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \
  1597                  "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \
  1598                  "($help)--disable-legacy-registry[Disable contacting legacy registries]" \
  1599                  "($help)*--dns=[DNS server to use]:DNS: " \
  1600                  "($help)*--dns-opt=[DNS options to use]:DNS option: " \
  1601                  "($help)*--dns-search=[DNS search domains to use]:DNS search: " \
  1602                  "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \
  1603                  "($help)--exec-root=[Root directory for execution state files]:path:_directories" \
  1604                  "($help)--experimental[Enable experimental features]" \
  1605                  "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \
  1606                  "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \
  1607                  "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \
  1608                  "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \
  1609                  "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
  1610                  "($help)--icc[Enable inter-container communication]" \
  1611                  "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \
  1612                  "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \
  1613                  "($help)--ip=[Default IP when binding container ports]" \
  1614                  "($help)--ip-forward[Enable net.ipv4.ip_forward]" \
  1615                  "($help)--ip-masq[Enable IP masquerading]" \
  1616                  "($help)--iptables[Enable addition of iptables rules]" \
  1617                  "($help)--ipv6[Enable IPv6 networking]" \
  1618                  "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
  1619                  "($help)*--label=[Key=value labels]:label: " \
  1620                  "($help)--live-restore[Enable live restore of docker when containers are still running]" \
  1621                  "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers" \
  1622                  "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_log_options" \
  1623                  "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \
  1624                  "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \
  1625                  "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \
  1626                  "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \
  1627                  "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \
  1628                  "($help)--raw-logs[Full timestamps without ANSI coloring]" \
  1629                  "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \
  1630                  "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \
  1631                  "($help)--selinux-enabled[Enable selinux support]" \
  1632                  "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \
  1633                  "($help)*--storage-opt=[Storage driver options]:storage driver options: " \
  1634                  "($help)--tls[Use TLS]" \
  1635                  "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \
  1636                  "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \
  1637                  "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \
  1638                  "($help)--tlsverify[Use TLS and verify the remote]" \
  1639                  "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \
  1640                  "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0
  1641  
  1642              case $state in
  1643                  (cluster-store)
  1644                      if compset -P '*://'; then
  1645                          _message 'host:port' && ret=0
  1646                      else
  1647                          store=('consul' 'etcd' 'zk')
  1648                          _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0
  1649                      fi
  1650                      ;;
  1651                  (cluster-store-options)
  1652                      if compset -P '*='; then
  1653                          _files && ret=0
  1654                      else
  1655                          opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path')
  1656                          _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0
  1657                      fi
  1658                      ;;
  1659                  (users-groups)
  1660                      if compset -P '*:'; then
  1661                          _groups && ret=0
  1662                      else
  1663                          _describe -t userns-default "default Docker user management" '(default)' && ret=0
  1664                          _users && ret=0
  1665                      fi
  1666                      ;;
  1667              esac
  1668              ;;
  1669          (diff)
  1670              _arguments $(__docker_arguments) \
  1671                  $opts_help \
  1672                  "($help -)*:containers:__docker_containers" && ret=0
  1673              ;;
  1674          (events)
  1675              _arguments $(__docker_arguments) \
  1676                  $opts_help \
  1677                  "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \
  1678                  "($help)--since=[Events created since this timestamp]:timestamp: " \
  1679                  "($help)--until=[Events created until this timestamp]:timestamp: " \
  1680                  "($help)--format=[Format the output using the given go template]:template: " && ret=0
  1681              ;;
  1682          (exec)
  1683              local state
  1684              _arguments $(__docker_arguments) \
  1685                  $opts_help \
  1686                  $opts_attach_exec_run_start \
  1687                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1688                  "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \
  1689                  "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \
  1690                  "($help)--privileged[Give extended Linux capabilities to the command]" \
  1691                  "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
  1692                  "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \
  1693                  "($help -):containers:__docker_runningcontainers" \
  1694                  "($help -)*::command:->anycommand" && ret=0
  1695  
  1696              case $state in
  1697                  (anycommand)
  1698                      shift 1 words
  1699                      (( CURRENT-- ))
  1700                      _normal && ret=0
  1701                      ;;
  1702              esac
  1703              ;;
  1704          (export)
  1705              _arguments $(__docker_arguments) \
  1706                  $opts_help \
  1707                  "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \
  1708                  "($help -)*:containers:__docker_containers" && ret=0
  1709              ;;
  1710          (history)
  1711              _arguments $(__docker_arguments) \
  1712                  $opts_help \
  1713                  "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \
  1714                  "($help)--no-trunc[Do not truncate output]" \
  1715                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1716                  "($help -)*: :__docker_images" && ret=0
  1717              ;;
  1718          (images)
  1719              _arguments $(__docker_arguments) \
  1720                  $opts_help \
  1721                  "($help -a --all)"{-a,--all}"[Show all images]" \
  1722                  "($help)--digests[Show digests]" \
  1723                  "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1724                  "($help)--format=[Pretty-print images using a Go template]:template: " \
  1725                  "($help)--no-trunc[Do not truncate output]" \
  1726                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1727                  "($help -): :__docker_repositories" && ret=0
  1728  
  1729              case $state in
  1730                  (filter-options)
  1731                      __docker_complete_images_filters && ret=0
  1732                      ;;
  1733              esac
  1734              ;;
  1735          (import)
  1736              _arguments $(__docker_arguments) \
  1737                  $opts_help \
  1738                  "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
  1739                  "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \
  1740                  "($help -):URL:(- http:// file://)" \
  1741                  "($help -): :__docker_repositories_with_tags" && ret=0
  1742              ;;
  1743          (info|version)
  1744              _arguments $(__docker_arguments) \
  1745                  $opts_help \
  1746                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0
  1747              ;;
  1748          (inspect)
  1749              local state
  1750              _arguments $(__docker_arguments) \
  1751                  $opts_help \
  1752                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1753                  "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \
  1754                  "($help)--type=[Return JSON for specified type]:type:(image container)" \
  1755                  "($help -)*: :->values" && ret=0
  1756  
  1757              case $state in
  1758                  (values)
  1759                      if [[ ${words[(r)--type=container]} == --type=container ]]; then
  1760                          __docker_containers && ret=0
  1761                      elif [[ ${words[(r)--type=image]} == --type=image ]]; then
  1762                          __docker_images && ret=0
  1763                      else
  1764                          __docker_images && __docker_containers && ret=0
  1765                      fi
  1766                      ;;
  1767              esac
  1768              ;;
  1769          (kill)
  1770              _arguments $(__docker_arguments) \
  1771                  $opts_help \
  1772                  "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \
  1773                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1774              ;;
  1775          (load)
  1776              _arguments $(__docker_arguments) \
  1777                  $opts_help \
  1778                  "($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))(-.)\"" \
  1779                  "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0
  1780              ;;
  1781          (login)
  1782              _arguments $(__docker_arguments) \
  1783                  $opts_help \
  1784                  "($help -p --password)"{-p=,--password=}"[Password]:password: " \
  1785                  "($help -u --user)"{-u=,--user=}"[Username]:username: " \
  1786                  "($help -)1:server: " && ret=0
  1787              ;;
  1788          (logout)
  1789              _arguments $(__docker_arguments) \
  1790                  $opts_help \
  1791                  "($help -)1:server: " && ret=0
  1792              ;;
  1793          (logs)
  1794              _arguments $(__docker_arguments) \
  1795                  $opts_help \
  1796                  "($help)--details[Show extra details provided to logs]" \
  1797                  "($help -f --follow)"{-f,--follow}"[Follow log output]" \
  1798                  "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \
  1799                  "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \
  1800                  "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \
  1801                  "($help -)*:containers:__docker_containers" && ret=0
  1802              ;;
  1803          (network)
  1804              local curcontext="$curcontext" state
  1805              _arguments $(__docker_arguments) \
  1806                  $opts_help \
  1807                  "($help -): :->command" \
  1808                  "($help -)*:: :->option-or-argument" && ret=0
  1809  
  1810              case $state in
  1811                  (command)
  1812                      __docker_network_commands && ret=0
  1813                      ;;
  1814                  (option-or-argument)
  1815                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1816                      __docker_network_subcommand && ret=0
  1817                      ;;
  1818              esac
  1819              ;;
  1820          (node)
  1821              local curcontext="$curcontext" state
  1822              _arguments $(__docker_arguments) \
  1823                  $opts_help \
  1824                  "($help -): :->command" \
  1825                  "($help -)*:: :->option-or-argument" && ret=0
  1826  
  1827              case $state in
  1828                  (command)
  1829                      __docker_node_commands && ret=0
  1830                      ;;
  1831                  (option-or-argument)
  1832                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1833                      __docker_node_subcommand && ret=0
  1834                      ;;
  1835              esac
  1836              ;;
  1837          (pause|unpause)
  1838              _arguments $(__docker_arguments) \
  1839                  $opts_help \
  1840                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1841              ;;
  1842          (plugin)
  1843              local curcontext="$curcontext" state
  1844              _arguments $(__docker_arguments) \
  1845                  $opts_help \
  1846                  "($help -): :->command" \
  1847                  "($help -)*:: :->option-or-argument" && ret=0
  1848  
  1849              case $state in
  1850                  (command)
  1851                      __docker_plugin_commands && ret=0
  1852                      ;;
  1853                  (option-or-argument)
  1854                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1855                      __docker_plugin_subcommand && ret=0
  1856                      ;;
  1857              esac
  1858              ;;
  1859          (port)
  1860              _arguments $(__docker_arguments) \
  1861                  $opts_help \
  1862                  "($help -)1:containers:__docker_runningcontainers" \
  1863                  "($help -)2:port:_ports" && ret=0
  1864              ;;
  1865          (ps)
  1866              _arguments $(__docker_arguments) \
  1867                  $opts_help \
  1868                  "($help -a --all)"{-a,--all}"[Show all containers]" \
  1869                  "($help)--before=[Show only container created before...]:containers:__docker_containers" \
  1870                  "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \
  1871                  "($help)--format=[Pretty-print containers using a Go template]:template: " \
  1872                  "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \
  1873                  "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \
  1874                  "($help)--no-trunc[Do not truncate output]" \
  1875                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1876                  "($help -s --size)"{-s,--size}"[Display total file sizes]" \
  1877                  "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0
  1878              ;;
  1879          (pull)
  1880              _arguments $(__docker_arguments) \
  1881                  $opts_help \
  1882                  "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \
  1883                  "($help)--disable-content-trust[Skip image verification]" \
  1884                  "($help -):name:__docker_search" && ret=0
  1885              ;;
  1886          (push)
  1887              _arguments $(__docker_arguments) \
  1888                  $opts_help \
  1889                  "($help)--disable-content-trust[Skip image signing]" \
  1890                  "($help -): :__docker_images" && ret=0
  1891              ;;
  1892          (rename)
  1893              _arguments $(__docker_arguments) \
  1894                  $opts_help \
  1895                  "($help -):old name:__docker_containers" \
  1896                  "($help -):new name: " && ret=0
  1897              ;;
  1898          (stop)
  1899              _arguments $(__docker_arguments) \
  1900                  $opts_help \
  1901                  "($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)" \
  1902                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1903              ;;
  1904          (restart)
  1905              _arguments $(__docker_arguments) \
  1906                  $opts_help \
  1907                  "($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)" \
  1908                  "($help -)*:containers:__docker_containers_ids" && ret=0
  1909              ;;
  1910          (rm)
  1911              _arguments $(__docker_arguments) \
  1912                  $opts_help \
  1913                  "($help -f --force)"{-f,--force}"[Force removal]" \
  1914                  "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \
  1915                  "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \
  1916                  "($help -)*:containers:->values" && ret=0
  1917              case $state in
  1918                  (values)
  1919                      if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then
  1920                          __docker_containers && ret=0
  1921                      else
  1922                          __docker_stoppedcontainers && ret=0
  1923                      fi
  1924                      ;;
  1925              esac
  1926              ;;
  1927          (rmi)
  1928              _arguments $(__docker_arguments) \
  1929                  $opts_help \
  1930                  "($help -f --force)"{-f,--force}"[Force removal]" \
  1931                  "($help)--no-prune[Do not delete untagged parents]" \
  1932                  "($help -)*: :__docker_images" && ret=0
  1933              ;;
  1934          (run)
  1935              _arguments $(__docker_arguments) \
  1936                  $opts_help \
  1937                  $opts_build_create_run \
  1938                  $opts_build_create_run_update \
  1939                  $opts_create_run \
  1940                  $opts_create_run_update \
  1941                  $opts_attach_exec_run_start \
  1942                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1943                  "($help)--health-cmd=[Command to run to check health]:command: " \
  1944                  "($help)--health-interval=[Time between running the check]:time: " \
  1945                  "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \
  1946                  "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \
  1947                  "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \
  1948                  "($help)--rm[Remove intermediate containers when it exits]" \
  1949                  "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \
  1950                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
  1951                  "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \
  1952                  "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \
  1953                  "($help -): :__docker_images" \
  1954                  "($help -):command: _command_names -e" \
  1955                  "($help -)*::arguments: _normal" && ret=0
  1956  
  1957              case $state in
  1958                  (link)
  1959                      if compset -P "*:"; then
  1960                          _wanted alias expl "Alias" compadd -E "" && ret=0
  1961                      else
  1962                          __docker_runningcontainers -qS ":" && ret=0
  1963                      fi
  1964                      ;;
  1965                  (storage-opt)
  1966                      if compset -P "*="; then
  1967                          _message "value" && ret=0
  1968                      else
  1969                          opts=('size')
  1970                          _describe -t filter-opts "storage options" opts -qS "=" && ret=0
  1971                      fi
  1972                      ;;
  1973              esac
  1974  
  1975              ;;
  1976          (save)
  1977              _arguments $(__docker_arguments) \
  1978                  $opts_help \
  1979                  "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \
  1980                  "($help -)*: :__docker_images" && ret=0
  1981              ;;
  1982          (search)
  1983              _arguments $(__docker_arguments) \
  1984                  $opts_help \
  1985                  "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1986                  "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \
  1987                  "($help)--no-trunc[Do not truncate output]" \
  1988                  "($help -):term: " && ret=0
  1989  
  1990              case $state in
  1991                  (filter-options)
  1992                      __docker_complete_search_filters && ret=0
  1993                      ;;
  1994              esac
  1995              ;;
  1996          (service)
  1997              local curcontext="$curcontext" state
  1998              _arguments $(__docker_arguments) \
  1999                  $opts_help \
  2000                  "($help -): :->command" \
  2001                  "($help -)*:: :->option-or-argument" && ret=0
  2002  
  2003              case $state in
  2004                  (command)
  2005                      __docker_service_commands && ret=0
  2006                      ;;
  2007                  (option-or-argument)
  2008                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  2009                      __docker_service_subcommand && ret=0
  2010                      ;;
  2011              esac
  2012              ;;
  2013          (start)
  2014              _arguments $(__docker_arguments) \
  2015                  $opts_help \
  2016                  $opts_attach_exec_run_start \
  2017                  "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \
  2018                  "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \
  2019                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
  2020              ;;
  2021          (stats)
  2022              _arguments $(__docker_arguments) \
  2023                  $opts_help \
  2024                  "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \
  2025                  "($help)--format=[Pretty-print images using a Go template]:template: " \
  2026                  "($help)--no-stream[Disable streaming stats and only pull the first result]" \
  2027                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  2028              ;;
  2029          (swarm)
  2030              local curcontext="$curcontext" state
  2031              _arguments $(__docker_arguments) \
  2032                  $opts_help \
  2033                  "($help -): :->command" \
  2034                  "($help -)*:: :->option-or-argument" && ret=0
  2035  
  2036              case $state in
  2037                  (command)
  2038                      __docker_swarm_commands && ret=0
  2039                      ;;
  2040                  (option-or-argument)
  2041                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  2042                      __docker_swarm_subcommand && ret=0
  2043                      ;;
  2044              esac
  2045              ;;
  2046          (tag)
  2047              _arguments $(__docker_arguments) \
  2048                  $opts_help \
  2049                  "($help -):source:__docker_images"\
  2050                  "($help -):destination:__docker_repositories_with_tags" && ret=0
  2051              ;;
  2052          (top)
  2053              _arguments $(__docker_arguments) \
  2054                  $opts_help \
  2055                  "($help -)1:containers:__docker_runningcontainers" \
  2056                  "($help -)*:: :->ps-arguments" && ret=0
  2057              case $state in
  2058                  (ps-arguments)
  2059                      _ps && ret=0
  2060                      ;;
  2061              esac
  2062  
  2063              ;;
  2064          (update)
  2065              _arguments $(__docker_arguments) \
  2066                  $opts_help \
  2067                  $opts_create_run_update \
  2068                  $opts_build_create_run_update \
  2069                  "($help -)*: :->values" && ret=0
  2070  
  2071              case $state in
  2072                  (values)
  2073                      if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then
  2074                          __docker_stoppedcontainers && ret=0
  2075                      else
  2076                          __docker_containers && ret=0
  2077                      fi
  2078                      ;;
  2079              esac
  2080              ;;
  2081          (volume)
  2082              local curcontext="$curcontext" state
  2083              _arguments $(__docker_arguments) \
  2084                  $opts_help \
  2085                  "($help -): :->command" \
  2086                  "($help -)*:: :->option-or-argument" && ret=0
  2087  
  2088              case $state in
  2089                  (command)
  2090                      __docker_volume_commands && ret=0
  2091                      ;;
  2092                  (option-or-argument)
  2093                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  2094                      __docker_volume_subcommand && ret=0
  2095                      ;;
  2096              esac
  2097              ;;
  2098          (wait)
  2099              _arguments $(__docker_arguments) \
  2100                  $opts_help \
  2101                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  2102              ;;
  2103          (help)
  2104              _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0
  2105              ;;
  2106      esac
  2107  
  2108      return ret
  2109  }
  2110  
  2111  _docker() {
  2112      # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
  2113      # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
  2114      if [[ $service != docker ]]; then
  2115          _call_function - _$service
  2116          return
  2117      fi
  2118  
  2119      local curcontext="$curcontext" state line help="-h --help"
  2120      integer ret=1
  2121      typeset -A opt_args
  2122  
  2123      _arguments $(__docker_arguments) -C \
  2124          "(: -)"{-h,--help}"[Print usage]" \
  2125          "($help)--config[Location of client config files]:path:_directories" \
  2126          "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
  2127          "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
  2128          "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
  2129          "($help)--tls[Use TLS]" \
  2130          "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
  2131          "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
  2132          "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
  2133          "($help)--tlsverify[Use TLS and verify the remote]" \
  2134          "($help)--userland-proxy[Use userland proxy for loopback traffic]" \
  2135          "($help -v --version)"{-v,--version}"[Print version information and quit]" \
  2136          "($help -): :->command" \
  2137          "($help -)*:: :->option-or-argument" && ret=0
  2138  
  2139      local host=${opt_args[-H]}${opt_args[--host]}
  2140      local config=${opt_args[--config]}
  2141      local docker_options="${host:+--host $host} ${config:+--config $config}"
  2142  
  2143      case $state in
  2144          (command)
  2145              __docker_commands && ret=0
  2146              ;;
  2147          (option-or-argument)
  2148              curcontext=${curcontext%:*:*}:docker-$words[1]:
  2149              __docker_subcommand && ret=0
  2150              ;;
  2151      esac
  2152  
  2153      return ret
  2154  }
  2155  
  2156  _dockerd() {
  2157      integer ret=1
  2158      words[1]='daemon'
  2159      __docker_subcommand && ret=0
  2160      return ret
  2161  }
  2162  
  2163  _docker "$@"
  2164  
  2165  # Local Variables:
  2166  # mode: Shell-Script
  2167  # sh-indentation: 4
  2168  # indent-tabs-mode: nil
  2169  # sh-basic-offset: 4
  2170  # End:
  2171  # vim: ft=zsh sw=4 ts=4 et