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