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