github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/contrib/completion/zsh/_docker (about)

     1  #compdef docker dockerd
     2  #
     3  # zsh completion for docker (http://docker.com)
     4  #
     5  # version:  0.3.0
     6  # github:   https://github.com/felixr/docker-zsh-completion
     7  #
     8  # contributors:
     9  #   - Felix Riedel
    10  #   - Steve Durrheimer
    11  #   - Vincent Bernat
    12  #
    13  # license:
    14  #
    15  # Copyright (c) 2013, Felix Riedel
    16  # All rights reserved.
    17  #
    18  # Redistribution and use in source and binary forms, with or without
    19  # modification, are permitted provided that the following conditions are met:
    20  #     * Redistributions of source code must retain the above copyright
    21  #       notice, this list of conditions and the following disclaimer.
    22  #     * Redistributions in binary form must reproduce the above copyright
    23  #       notice, this list of conditions and the following disclaimer in the
    24  #       documentation and/or other materials provided with the distribution.
    25  #     * Neither the name of the <organization> nor the
    26  #       names of its contributors may be used to endorse or promote products
    27  #       derived from this software without specific prior written permission.
    28  #
    29  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    30  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    31  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    32  # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
    33  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    34  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    35  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    36  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    37  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    38  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    39  #
    40  
    41  # Short-option stacking can be enabled with:
    42  #  zstyle ':completion:*:*:docker:*' option-stacking yes
    43  #  zstyle ':completion:*:*:docker-*:*' option-stacking yes
    44  __docker_arguments() {
    45      if zstyle -t ":completion:${curcontext}:" option-stacking; then
    46          print -- -s
    47      fi
    48  }
    49  
    50  __docker_get_containers() {
    51      [[ $PREFIX = -* ]] && return 1
    52      integer ret=1
    53      local kind type line s
    54      declare -a running stopped lines args names
    55  
    56      kind=$1; shift
    57      type=$1; shift
    58      [[ $kind = (stopped|all) ]] && args=($args -a)
    59  
    60      lines=(${(f)"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"})
    61  
    62      # Parse header line to find columns
    63      local i=1 j=1 k header=${lines[1]}
    64      declare -A begin end
    65      while (( j < ${#header} - 1 )); do
    66          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
    67          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
    68          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
    69          begin[${header[$i,$((j-1))]}]=$i
    70          end[${header[$i,$((j-1))]}]=$k
    71      done
    72      end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line
    73      lines=(${lines[2,-1]})
    74  
    75      # Container ID
    76      if [[ $type = (ids|all) ]]; then
    77          for line in $lines; do
    78              s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}"
    79              s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
    80              s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
    81              if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
    82                  stopped=($stopped $s)
    83              else
    84                  running=($running $s)
    85              fi
    86          done
    87      fi
    88  
    89      # Names: we only display the one without slash. All other names
    90      # are generated and may clutter the completion. However, with
    91      # Swarm, all names may be prefixed by the swarm node name.
    92      if [[ $type = (names|all) ]]; then
    93          for line in $lines; do
    94              names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}})
    95              # First step: find a common prefix and strip it (swarm node case)
    96              (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/}
    97              # Second step: only keep the first name without a /
    98              s=${${names:#*/*}[1]}
    99              # If no name, well give up.
   100              (( $#s != 0 )) || continue
   101              s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
   102              s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
   103              if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
   104                  stopped=($stopped $s)
   105              else
   106                  running=($running $s)
   107              fi
   108          done
   109      fi
   110  
   111      [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0
   112      [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0
   113      return ret
   114  }
   115  
   116  __docker_stoppedcontainers() {
   117      [[ $PREFIX = -* ]] && return 1
   118      __docker_get_containers stopped all "$@"
   119  }
   120  
   121  __docker_runningcontainers() {
   122      [[ $PREFIX = -* ]] && return 1
   123      __docker_get_containers running all "$@"
   124  }
   125  
   126  __docker_containers() {
   127      [[ $PREFIX = -* ]] && return 1
   128      __docker_get_containers all all "$@"
   129  }
   130  
   131  __docker_containers_ids() {
   132      [[ $PREFIX = -* ]] && return 1
   133      __docker_get_containers all ids "$@"
   134  }
   135  
   136  __docker_containers_names() {
   137      [[ $PREFIX = -* ]] && return 1
   138      __docker_get_containers all names "$@"
   139  }
   140  
   141  __docker_plugins() {
   142      [[ $PREFIX = -* ]] && return 1
   143      integer ret=1
   144      emulate -L zsh
   145      setopt extendedglob
   146      local -a plugins
   147      plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: })
   148      _describe -t plugins "$1 plugins" plugins && ret=0
   149      return ret
   150  }
   151  
   152  __docker_images() {
   153      [[ $PREFIX = -* ]] && return 1
   154      integer ret=1
   155      declare -a images
   156      images=(${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}})
   157      _describe -t docker-images "images" images && ret=0
   158      __docker_repositories_with_tags && ret=0
   159      return ret
   160  }
   161  
   162  __docker_repositories() {
   163      [[ $PREFIX = -* ]] && return 1
   164      declare -a repos
   165      repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]})
   166      repos=(${repos#<none>})
   167      _describe -t docker-repos "repositories" repos
   168  }
   169  
   170  __docker_repositories_with_tags() {
   171      [[ $PREFIX = -* ]] && return 1
   172      integer ret=1
   173      declare -a repos onlyrepos matched
   174      declare m
   175      repos=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/:::}%% *})
   176      repos=(${${repos%:::<none>}#<none>})
   177      # Check if we have a prefix-match for the current prefix.
   178      onlyrepos=(${repos%::*})
   179      for m in $onlyrepos; do
   180          [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && {
   181              # Yes, complete with tags
   182              repos=(${${repos/:::/:}/:/\\:})
   183              _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0
   184              return ret
   185          }
   186      done
   187      # No, only complete repositories
   188      onlyrepos=(${${repos%:::*}/:/\\:})
   189      _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0
   190  
   191      return ret
   192  }
   193  
   194  __docker_search() {
   195      [[ $PREFIX = -* ]] && return 1
   196      local cache_policy
   197      zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
   198      if [[ -z "$cache_policy" ]]; then
   199          zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
   200      fi
   201  
   202      local searchterm cachename
   203      searchterm="${words[$CURRENT]%/}"
   204      cachename=_docker-search-$searchterm
   205  
   206      local expl
   207      local -a result
   208      if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \
   209          && ! _retrieve_cache ${cachename#_}; then
   210          _message "Searching for ${searchterm}..."
   211          result=(${${${(f)"$(_call_program commands docker $docker_options search $searchterm)"}%% *}[2,-1]})
   212          _store_cache ${cachename#_} result
   213      fi
   214      _wanted dockersearch expl 'available images' compadd -a result
   215  }
   216  
   217  __docker_get_log_options() {
   218      [[ $PREFIX = -* ]] && return 1
   219  
   220      integer ret=1
   221      local log_driver=${opt_args[--log-driver]:-"all"}
   222      local -a awslogs_options fluentd_options gelf_options journald_options json_file_options syslog_options splunk_options
   223  
   224      awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream")
   225      fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag")
   226      gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels")
   227      gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag")
   228      journald_options=("env" "labels" "tag")
   229      json_file_options=("env" "labels" "max-file" "max-size")
   230      syslog_options=("syslog-address" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "syslog-facility" "tag")
   231      splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "tag")
   232  
   233      [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0
   234      [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0
   235      [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0
   236      [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0
   237      [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0
   238      [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0
   239      [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0
   240      [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0
   241  
   242      return ret
   243  }
   244  
   245  __docker_log_options() {
   246      [[ $PREFIX = -* ]] && return 1
   247      integer ret=1
   248  
   249      if compset -P '*='; then
   250          case "${${words[-1]%=*}#*=}" in
   251              (syslog-format)
   252                  syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro')
   253                  _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0
   254                  ;;
   255              *)
   256                  _message 'value' && ret=0
   257                  ;;
   258          esac
   259      else
   260          __docker_get_log_options -qS "=" && ret=0
   261      fi
   262  
   263      return ret
   264  }
   265  
   266  __docker_complete_detach_keys() {
   267      [[ $PREFIX = -* ]] && return 1
   268      integer ret=1
   269  
   270      compset -P "*,"
   271      keys=(${:-{a-z}})
   272      ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}})
   273      _describe -t detach_keys "[a-z]" keys -qS "," && ret=0
   274      _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0
   275  }
   276  
   277  __docker_complete_pid() {
   278      [[ $PREFIX = -* ]] && return 1
   279      integer ret=1
   280      local -a opts vopts
   281  
   282      opts=('host')
   283      vopts=('container')
   284  
   285      if compset -P '*:'; then
   286          case "${${words[-1]%:*}#*=}" in
   287              (container)
   288                  __docker_runningcontainers && ret=0
   289                  ;;
   290              *)
   291                  _message 'value' && ret=0
   292                  ;;
   293          esac
   294      else
   295          _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0
   296          _describe -t pid-opts "PID Options" opts && ret=0
   297      fi
   298  
   299      return ret
   300  }
   301  
   302  __docker_complete_ps_filters() {
   303      [[ $PREFIX = -* ]] && return 1
   304      integer ret=1
   305  
   306      if compset -P '*='; then
   307          case "${${words[-1]%=*}#*=}" in
   308              (ancestor)
   309                  __docker_images && ret=0
   310                  ;;
   311              (before|since)
   312                  __docker_containers && ret=0
   313                  ;;
   314              (id)
   315                  __docker_containers_ids && ret=0
   316                  ;;
   317              (name)
   318                  __docker_containers_names && ret=0
   319                  ;;
   320              (network)
   321                  __docker_networks && ret=0
   322                  ;;
   323              (status)
   324                  status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running')
   325                  _describe -t status-filter-opts "Status Filter Options" status_opts && ret=0
   326                  ;;
   327              (volume)
   328                  __docker_volumes && ret=0
   329                  ;;
   330              *)
   331                  _message 'value' && ret=0
   332                  ;;
   333          esac
   334      else
   335          opts=('ancestor' 'before' 'exited' 'id' 'label' 'name' 'network' 'since' 'status' 'volume')
   336          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
   337      fi
   338  
   339      return ret
   340  }
   341  
   342  __docker_complete_search_filters() {
   343      [[ $PREFIX = -* ]] && return 1
   344      integer ret=1
   345      declare -a boolean_opts opts
   346  
   347      boolean_opts=('true' 'false')
   348      opts=('is-automated' 'is-official' 'stars')
   349  
   350      if compset -P '*='; then
   351          case "${${words[-1]%=*}#*=}" in
   352              (is-automated|is-official)
   353                  _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
   354                  ;;
   355              *)
   356                  _message 'value' && ret=0
   357                  ;;
   358          esac
   359      else
   360          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
   361      fi
   362  
   363      return ret
   364  }
   365  
   366  __docker_complete_images_filters() {
   367      [[ $PREFIX = -* ]] && return 1
   368      integer ret=1
   369      declare -a boolean_opts opts
   370  
   371      boolean_opts=('true' 'false')
   372      opts=('before' 'dangling' 'label' 'since')
   373  
   374      if compset -P '*='; then
   375          case "${${words[-1]%=*}#*=}" in
   376              (before|since)
   377                  __docker_images && ret=0
   378                  ;;
   379              (dangling)
   380                  _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
   381                  ;;
   382              *)
   383                  _message 'value' && ret=0
   384                  ;;
   385          esac
   386      else
   387          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
   388      fi
   389  
   390      return ret
   391  }
   392  
   393  __docker_complete_events_filter() {
   394      [[ $PREFIX = -* ]] && return 1
   395      integer ret=1
   396      declare -a opts
   397  
   398      opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume')
   399  
   400      if compset -P '*='; then
   401          case "${${words[-1]%=*}#*=}" in
   402              (container)
   403                  __docker_containers && ret=0
   404                  ;;
   405              (daemon)
   406                  emulate -L zsh
   407                  setopt extendedglob
   408                  local -a daemon_opts
   409                  daemon_opts=(
   410                      ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}}
   411                      ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:}
   412                  )
   413                  _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0
   414                  ;;
   415              (event)
   416                  local -a event_opts
   417                  event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach'
   418                  'exec_start' 'export' 'import' 'kill' 'load'  'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start'
   419                  'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update')
   420                  _describe -t event-filter-opts "event filter options" event_opts && ret=0
   421                  ;;
   422              (image)
   423                  __docker_images && ret=0
   424                  ;;
   425              (network)
   426                  __docker_networks && ret=0
   427                  ;;
   428              (type)
   429                  local -a type_opts
   430                  type_opts=('container' 'daemon' 'image' 'network' 'volume')
   431                  _describe -t type-filter-opts "type filter options" type_opts && ret=0
   432                  ;;
   433              (volume)
   434                  __docker_volumes && ret=0
   435                  ;;
   436              *)
   437                  _message 'value' && ret=0
   438                  ;;
   439          esac
   440      else
   441          _describe -t filter-opts "filter options" opts -qS "=" && ret=0
   442      fi
   443  
   444      return ret
   445  }
   446  
   447  __docker_network_complete_ls_filters() {
   448      [[ $PREFIX = -* ]] && return 1
   449      integer ret=1
   450  
   451      if compset -P '*='; then
   452          case "${${words[-1]%=*}#*=}" in
   453              (driver)
   454                  __docker_plugins Network && ret=0
   455                  ;;
   456              (id)
   457                  __docker_networks_ids && ret=0
   458                  ;;
   459              (name)
   460                  __docker_networks_names && ret=0
   461                  ;;
   462              (type)
   463                  type_opts=('builtin' 'custom')
   464                  _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0
   465                  ;;
   466              *)
   467                  _message 'value' && ret=0
   468                  ;;
   469          esac
   470      else
   471          opts=('driver' 'id' 'label' 'name' 'type')
   472          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
   473      fi
   474  
   475      return ret
   476  }
   477  
   478  __docker_get_networks() {
   479      [[ $PREFIX = -* ]] && return 1
   480      integer ret=1
   481      local line s
   482      declare -a lines networks
   483  
   484      type=$1; shift
   485  
   486      lines=(${(f)"$(_call_program commands docker $docker_options network ls)"})
   487  
   488      # Parse header line to find columns
   489      local i=1 j=1 k header=${lines[1]}
   490      declare -A begin end
   491      while (( j < ${#header} - 1 )); do
   492          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
   493          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
   494          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
   495          begin[${header[$i,$((j-1))]}]=$i
   496          end[${header[$i,$((j-1))]}]=$k
   497      done
   498      end[${header[$i,$((j-1))]}]=-1
   499      lines=(${lines[2,-1]})
   500  
   501      # Network ID
   502      if [[ $type = (ids|all) ]]; then
   503          for line in $lines; do
   504              s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}"
   505              s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   506              networks=($networks $s)
   507          done
   508      fi
   509  
   510      # Names
   511      if [[ $type = (names|all) ]]; then
   512          for line in $lines; do
   513              s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
   514              s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   515              networks=($networks $s)
   516          done
   517      fi
   518  
   519      _describe -t networks-list "networks" networks "$@" && ret=0
   520      return ret
   521  }
   522  
   523  __docker_networks() {
   524      [[ $PREFIX = -* ]] && return 1
   525      __docker_get_networks all "$@"
   526  }
   527  
   528  __docker_networks_ids() {
   529      [[ $PREFIX = -* ]] && return 1
   530      __docker_get_networks ids "$@"
   531  }
   532  
   533  __docker_networks_names() {
   534      [[ $PREFIX = -* ]] && return 1
   535      __docker_get_networks names "$@"
   536  }
   537  
   538  __docker_network_commands() {
   539      local -a _docker_network_subcommands
   540      _docker_network_subcommands=(
   541          "connect:Connects a container to a network"
   542          "create:Creates a new network with a name specified by the user"
   543          "disconnect:Disconnects a container from a network"
   544          "inspect:Displays detailed information on a network"
   545          "ls:Lists all the networks created by the user"
   546          "rm:Deletes one or more networks"
   547      )
   548      _describe -t docker-network-commands "docker network command" _docker_network_subcommands
   549  }
   550  
   551  __docker_network_subcommand() {
   552      local -a _command_args opts_help
   553      local expl help="--help"
   554      integer ret=1
   555  
   556      opts_help=("(: -)--help[Print usage]")
   557  
   558      case "$words[1]" in
   559          (connect)
   560              _arguments $(__docker_arguments) \
   561                  $opts_help \
   562                  "($help)*--alias=[Add network-scoped alias for the container]:alias: " \
   563                  "($help)--ip=[Container IPv4 address]:IPv4: " \
   564                  "($help)--ip6=[Container IPv6 address]:IPv6: " \
   565                  "($help)*--link=[Add a link to another container]:link:->link" \
   566                  "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \
   567                  "($help -)1:network:__docker_networks" \
   568                  "($help -)2:containers:__docker_containers" && ret=0
   569  
   570              case $state in
   571                  (link)
   572                      if compset -P "*:"; then
   573                          _wanted alias expl "Alias" compadd -E "" && ret=0
   574                      else
   575                          __docker_runningcontainers -qS ":" && ret=0
   576                      fi
   577                      ;;
   578              esac
   579              ;;
   580          (create)
   581              _arguments $(__docker_arguments) -A '-*' \
   582                  $opts_help \
   583                  "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \
   584                  "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \
   585                  "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \
   586                  "($help)--internal[Restricts external access to the network]" \
   587                  "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \
   588                  "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \
   589                  "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \
   590                  "($help)--ipv6[Enable IPv6 networking]" \
   591                  "($help)*--label=[Set metadata on a network]:label=value: " \
   592                  "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \
   593                  "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \
   594                  "($help -)1:Network Name: " && ret=0
   595              ;;
   596          (disconnect)
   597              _arguments $(__docker_arguments) \
   598                  $opts_help \
   599                  "($help -)1:network:__docker_networks" \
   600                  "($help -)2:containers:__docker_containers" && ret=0
   601              ;;
   602          (inspect)
   603              _arguments $(__docker_arguments) \
   604                  $opts_help \
   605                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
   606                  "($help -)*:network:__docker_networks" && ret=0
   607              ;;
   608          (ls)
   609              _arguments $(__docker_arguments) \
   610                  $opts_help \
   611                  "($help)--no-trunc[Do not truncate the output]" \
   612                  "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
   613                  "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0
   614              case $state in
   615                  (filter-options)
   616                      __docker_network_complete_ls_filters && ret=0
   617                      ;;
   618              esac
   619              ;;
   620          (rm)
   621              _arguments $(__docker_arguments) \
   622                  $opts_help \
   623                  "($help -)*:network:__docker_networks" && ret=0
   624              ;;
   625          (help)
   626              _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
   627              ;;
   628      esac
   629  
   630      return ret
   631  }
   632  
   633  __docker_volume_complete_ls_filters() {
   634      [[ $PREFIX = -* ]] && return 1
   635      integer ret=1
   636  
   637      if compset -P '*='; then
   638          case "${${words[-1]%=*}#*=}" in
   639              (dangling)
   640                  dangling_opts=('true' 'false')
   641                  _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0
   642                  ;;
   643              (driver)
   644                  __docker_plugins Volume && ret=0
   645                  ;;
   646              (name)
   647                  __docker_volumes && ret=0
   648                  ;;
   649              *)
   650                  _message 'value' && ret=0
   651                  ;;
   652          esac
   653      else
   654          opts=('dangling' 'driver' 'name')
   655          _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
   656      fi
   657  
   658      return ret
   659  }
   660  
   661  __docker_volumes() {
   662      [[ $PREFIX = -* ]] && return 1
   663      integer ret=1
   664      declare -a lines volumes
   665  
   666      lines=(${(f)"$(_call_program commands docker $docker_options volume ls)"})
   667  
   668      # Parse header line to find columns
   669      local i=1 j=1 k header=${lines[1]}
   670      declare -A begin end
   671      while (( j < ${#header} - 1 )); do
   672          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
   673          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
   674          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
   675          begin[${header[$i,$((j-1))]}]=$i
   676          end[${header[$i,$((j-1))]}]=$k
   677      done
   678      end[${header[$i,$((j-1))]}]=-1
   679      lines=(${lines[2,-1]})
   680  
   681      # Names
   682      local line s
   683      for line in $lines; do
   684          s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}"
   685          s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   686          volumes=($volumes $s)
   687      done
   688  
   689      _describe -t volumes-list "volumes" volumes && ret=0
   690      return ret
   691  }
   692  
   693  __docker_volume_commands() {
   694      local -a _docker_volume_subcommands
   695      _docker_volume_subcommands=(
   696          "create:Create a volume"
   697          "inspect:Return low-level information on a volume"
   698          "ls:List volumes"
   699          "rm:Remove a volume"
   700      )
   701      _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands
   702  }
   703  
   704  __docker_volume_subcommand() {
   705      local -a _command_args opts_help
   706      local expl help="--help"
   707      integer ret=1
   708  
   709      opts_help=("(: -)--help[Print usage]")
   710  
   711      case "$words[1]" in
   712          (create)
   713              _arguments $(__docker_arguments) \
   714                  $opts_help \
   715                  "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \
   716                  "($help)*--label=[Set metadata for a volume]:label=value: " \
   717                  "($help)--name=[Volume name]" \
   718                  "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " && ret=0
   719              ;;
   720          (inspect)
   721              _arguments $(__docker_arguments) \
   722                  $opts_help \
   723                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
   724                  "($help -)1:volume:__docker_volumes" && ret=0
   725              ;;
   726          (ls)
   727              _arguments $(__docker_arguments) \
   728                  $opts_help \
   729                  "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
   730                  "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0
   731              case $state in
   732                  (filter-options)
   733                      __docker_volume_complete_ls_filters && ret=0
   734                      ;;
   735              esac
   736              ;;
   737          (rm)
   738              _arguments $(__docker_arguments) \
   739                  $opts_help \
   740                  "($help -):volume:__docker_volumes" && ret=0
   741              ;;
   742          (help)
   743              _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0
   744              ;;
   745      esac
   746  
   747      return ret
   748  }
   749  
   750  __docker_caching_policy() {
   751    oldp=( "$1"(Nmh+1) )     # 1 hour
   752    (( $#oldp ))
   753  }
   754  
   755  __docker_commands() {
   756      local cache_policy
   757  
   758      zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
   759      if [[ -z "$cache_policy" ]]; then
   760          zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
   761      fi
   762  
   763      if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \
   764          && ! _retrieve_cache docker_subcommands;
   765      then
   766          local -a lines
   767          lines=(${(f)"$(_call_program commands docker 2>&1)"})
   768          _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I)    *]}]}## #}/ ##/:})
   769          _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command')
   770          (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands
   771      fi
   772      _describe -t docker-commands "docker command" _docker_subcommands
   773  }
   774  
   775  __docker_subcommand() {
   776      local -a _command_args opts_help opts_build_create_run opts_build_create_run_update opts_create_run opts_create_run_update
   777      local expl help="--help"
   778      integer ret=1
   779  
   780      opts_help=("(: -)--help[Print usage]")
   781      opts_build_create_run=(
   782          "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: "
   783          "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)"
   784          "($help)--disable-content-trust[Skip image verification]"
   785          "($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: "
   786          "($help)*--ulimit=[ulimit options]:ulimit: "
   787          "($help)--userns=[Container user namespace]:user namespace:(host)"
   788      )
   789      opts_build_create_run_update=(
   790          "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)"
   791          "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: "
   792          "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: "
   793          "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: "
   794          "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: "
   795          "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: "
   796          "($help)--memory-swap=[Total memory limit with swap]:Memory limit: "
   797      )
   798      opts_create_run=(
   799          "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
   800          "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: "
   801          "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: "
   802          "($help)*--cap-add=[Add Linux capabilities]:capability: "
   803          "($help)*--cap-drop=[Drop Linux capabilities]:capability: "
   804          "($help)--cidfile=[Write the container ID to the file]:CID file:_files"
   805          "($help)*--device=[Add a host device to the container]:device:_files"
   806          "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: "
   807          "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: "
   808          "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: "
   809          "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: "
   810          "($help)*--dns=[Custom DNS servers]:DNS server: "
   811          "($help)*--dns-opt=[Custom DNS options]:DNS option: "
   812          "($help)*--dns-search=[Custom DNS search domains]:DNS domains: "
   813          "($help)*"{-e=,--env=}"[Environment variables]:environment variable: "
   814          "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: "
   815          "($help)*--env-file=[Read environment variables from a file]:environment file:_files"
   816          "($help)*--expose=[Expose a port from the container without publishing it]: "
   817          "($help)*--group-add=[Add additional groups to run as]:group:_groups"
   818          "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts"
   819          "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]"
   820          "($help)--ip=[Container IPv4 address]:IPv4: "
   821          "($help)--ip6=[Container IPv6 address]:IPv6: "
   822          "($help)--ipc=[IPC namespace to use]:IPC namespace: "
   823          "($help)*--link=[Add link to another container]:link:->link"
   824          "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: "
   825          "($help)*"{-l=,--label=}"[Container metadata]:label: "
   826          "($help)--log-driver=[Default driver for container logs]:Logging driver:(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog)"
   827          "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options"
   828          "($help)--mac-address=[Container MAC address]:MAC address: "
   829          "($help)--name=[Container name]:name: "
   830          "($help)--net=[Connect a container to a network]:network mode:(bridge none container host)"
   831          "($help)*--net-alias=[Add network-scoped alias for the container]:alias: "
   832          "($help)--oom-kill-disable[Disable OOM Killer]"
   833          "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]"
   834          "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]"
   835          "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
   836          "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports"
   837          "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid"
   838          "($help)--privileged[Give extended privileges to this container]"
   839          "($help)--read-only[Mount the container's root filesystem as read only]"
   840          "($help)*--security-opt=[Security options]:security option: "
   841          "($help)*--sysctl=-[sysctl options]:sysctl: "
   842          "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]"
   843          "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
   844          "($help)--tmpfs[mount tmpfs]"
   845          "($help)*-v[Bind mount a volume]:volume: "
   846          "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)"
   847          "($help)*--volumes-from=[Mount volumes from the specified container]:volume: "
   848          "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
   849      )
   850      opts_create_run_update=(
   851          "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)"
   852          "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: "
   853          "($help)--memory-reservation=[Memory soft limit]:Memory limit: "
   854          "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)"
   855      )
   856      opts_attach_exec_run_start=(
   857          "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys"
   858      )
   859  
   860      case "$words[1]" in
   861          (attach)
   862              _arguments $(__docker_arguments) \
   863                  $opts_help \
   864                  $opts_attach_exec_run_start \
   865                  "($help)--no-stdin[Do not attach stdin]" \
   866                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
   867                  "($help -):containers:__docker_runningcontainers" && ret=0
   868              ;;
   869          (build)
   870              _arguments $(__docker_arguments) \
   871                  $opts_help \
   872                  $opts_build_create_run \
   873                  $opts_build_create_run_update \
   874                  "($help)*--build-arg[Build-time variables]:<varname>=<value>: " \
   875                  "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \
   876                  "($help)--force-rm[Always remove intermediate containers]" \
   877                  "($help)*--label=[Set metadata for an image]:label=value: " \
   878                  "($help)--no-cache[Do not use cache when building the image]" \
   879                  "($help)--pull[Attempt to pull a newer version of the image]" \
   880                  "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \
   881                  "($help)--rm[Remove intermediate containers after a successful build]" \
   882                  "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \
   883                  "($help -):path or URL:_directories" && ret=0
   884              ;;
   885          (commit)
   886              _arguments $(__docker_arguments) \
   887                  $opts_help \
   888                  "($help -a --author)"{-a=,--author=}"[Author]:author: " \
   889                  "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
   890                  "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \
   891                  "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \
   892                  "($help -):container:__docker_containers" \
   893                  "($help -): :__docker_repositories_with_tags" && ret=0
   894              ;;
   895          (cp)
   896              _arguments $(__docker_arguments) \
   897                  $opts_help \
   898                  "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \
   899                  "($help -)1:container:->container" \
   900                  "($help -)2:hostpath:_files" && ret=0
   901              case $state in
   902                  (container)
   903                      if compset -P "*:"; then
   904                          _files && ret=0
   905                      else
   906                          __docker_containers -qS ":" && ret=0
   907                      fi
   908                      ;;
   909              esac
   910              ;;
   911          (create)
   912              _arguments $(__docker_arguments) \
   913                  $opts_help \
   914                  $opts_build_create_run \
   915                  $opts_build_create_run_update \
   916                  $opts_create_run \
   917                  $opts_create_run_update \
   918                  "($help -): :__docker_images" \
   919                  "($help -):command: _command_names -e" \
   920                  "($help -)*::arguments: _normal" && ret=0
   921  
   922              case $state in
   923                  (link)
   924                      if compset -P "*:"; then
   925                          _wanted alias expl "Alias" compadd -E "" && ret=0
   926                      else
   927                          __docker_runningcontainers -qS ":" && ret=0
   928                      fi
   929                      ;;
   930              esac
   931  
   932              ;;
   933          (daemon)
   934              _arguments $(__docker_arguments) \
   935                  $opts_help \
   936                  "($help)--api-cors-header=[CORS headers in the remote API]:CORS headers: " \
   937                  "($help)*--authorization-plugin=[Authorization plugins to load]" \
   938                  "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \
   939                  "($help)--bip=[Network bridge IP]:IP address: " \
   940                  "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \
   941                  "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \
   942                  "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \
   943                  "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
   944                  "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \
   945                  "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \
   946                  "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \
   947                  "($help)--cluster-advertise=[Address of the daemon instance to advertise]:Instance to advertise (host\:port): " \
   948                  "($help)*--cluster-store-opt=[Cluster options]:Cluster options:->cluster-store-options" \
   949                  "($help)*--dns=[DNS server to use]:DNS: " \
   950                  "($help)*--dns-search=[DNS search domains to use]:DNS search: " \
   951                  "($help)*--dns-opt=[DNS options to use]:DNS option: " \
   952                  "($help)*--default-ulimit=[Default ulimit settings for containers]:ulimit: " \
   953                  "($help)--disable-legacy-registry[Do not contact legacy registries]" \
   954                  "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \
   955                  "($help)--exec-root=[Root directory for execution state files]:path:_directories" \
   956                  "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \
   957                  "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \
   958                  "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \
   959                  "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \
   960                  "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
   961                  "($help)--icc[Enable inter-container communication]" \
   962                  "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \
   963                  "($help)--ip=[Default IP when binding container ports]" \
   964                  "($help)--ip-forward[Enable net.ipv4.ip_forward]" \
   965                  "($help)--ip-masq[Enable IP masquerading]" \
   966                  "($help)--iptables[Enable addition of iptables rules]" \
   967                  "($help)--ipv6[Enable IPv6 networking]" \
   968                  "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
   969                  "($help)*--label=[Key=value labels]:label: " \
   970                  "($help)--live-restore[Enable live restore of docker when containers are still running]" \
   971                  "($help)--log-driver=[Default driver for container logs]:Logging driver:(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog)" \
   972                  "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" \
   973                  "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \
   974                  "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \
   975                  "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \
   976                  "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \
   977                  "($help)--raw-logs[Full timestamps without ANSI coloring]" \
   978                  "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \
   979                  "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \
   980                  "($help)--selinux-enabled[Enable selinux support]" \
   981                  "($help)*--storage-opt=[Storage driver options]:storage driver options: " \
   982                  "($help)--tls[Use TLS]" \
   983                  "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \
   984                  "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \
   985                  "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \
   986                  "($help)--tlsverify[Use TLS and verify the remote]" \
   987                  "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \
   988                  "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0
   989  
   990              case $state in
   991                  (cluster-store)
   992                      if compset -P '*://'; then
   993                          _message 'host:port' && ret=0
   994                      else
   995                          store=('consul' 'etcd' 'zk')
   996                          _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0
   997                      fi
   998                      ;;
   999                  (cluster-store-options)
  1000                      if compset -P '*='; then
  1001                          _files && ret=0
  1002                      else
  1003                          opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path')
  1004                          _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0
  1005                      fi
  1006                      ;;
  1007                  (users-groups)
  1008                      if compset -P '*:'; then
  1009                          _groups && ret=0
  1010                      else
  1011                          _describe -t userns-default "default Docker user management" '(default)' && ret=0
  1012                          _users && ret=0
  1013                      fi
  1014                      ;;
  1015              esac
  1016              ;;
  1017          (diff)
  1018              _arguments $(__docker_arguments) \
  1019                  $opts_help \
  1020                  "($help -)*:containers:__docker_containers" && ret=0
  1021              ;;
  1022          (events)
  1023              _arguments $(__docker_arguments) \
  1024                  $opts_help \
  1025                  "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \
  1026                  "($help)--since=[Events created since this timestamp]:timestamp: " \
  1027                  "($help)--until=[Events created until this timestamp]:timestamp: " && ret=0
  1028              ;;
  1029          (exec)
  1030              local state
  1031              _arguments $(__docker_arguments) \
  1032                  $opts_help \
  1033                  $opts_attach_exec_run_start \
  1034                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1035                  "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \
  1036                  "($help)--privileged[Give extended Linux capabilities to the command]" \
  1037                  "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
  1038                  "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \
  1039                  "($help -):containers:__docker_runningcontainers" \
  1040                  "($help -)*::command:->anycommand" && ret=0
  1041  
  1042              case $state in
  1043                  (anycommand)
  1044                      shift 1 words
  1045                      (( CURRENT-- ))
  1046                      _normal && ret=0
  1047                      ;;
  1048              esac
  1049              ;;
  1050          (export)
  1051              _arguments $(__docker_arguments) \
  1052                  $opts_help \
  1053                  "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \
  1054                  "($help -)*:containers:__docker_containers" && ret=0
  1055              ;;
  1056          (history)
  1057              _arguments $(__docker_arguments) \
  1058                  $opts_help \
  1059                  "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \
  1060                  "($help)--no-trunc[Do not truncate output]" \
  1061                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1062                  "($help -)*: :__docker_images" && ret=0
  1063              ;;
  1064          (images)
  1065              _arguments $(__docker_arguments) \
  1066                  $opts_help \
  1067                  "($help -a --all)"{-a,--all}"[Show all images]" \
  1068                  "($help)--digests[Show digests]" \
  1069                  "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1070                  "($help)--format[Pretty-print containers using a Go template]:format: " \
  1071                  "($help)--no-trunc[Do not truncate output]" \
  1072                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1073                  "($help -): :__docker_repositories" && ret=0
  1074  
  1075              case $state in
  1076                  (filter-options)
  1077                      __docker_complete_images_filters && ret=0
  1078                      ;;
  1079              esac
  1080              ;;
  1081          (import)
  1082              _arguments $(__docker_arguments) \
  1083                  $opts_help \
  1084                  "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
  1085                  "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \
  1086                  "($help -):URL:(- http:// file://)" \
  1087                  "($help -): :__docker_repositories_with_tags" && ret=0
  1088              ;;
  1089          (info|version)
  1090              _arguments $(__docker_arguments) \
  1091                  $opts_help && ret=0
  1092              ;;
  1093          (inspect)
  1094              local state
  1095              _arguments $(__docker_arguments) \
  1096                  $opts_help \
  1097                  "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1098                  "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \
  1099                  "($help)--type=[Return JSON for specified type]:type:(image container)" \
  1100                  "($help -)*: :->values" && ret=0
  1101  
  1102              case $state in
  1103                  (values)
  1104                      if [[ ${words[(r)--type=container]} == --type=container ]]; then
  1105                          __docker_containers && ret=0
  1106                      elif [[ ${words[(r)--type=image]} == --type=image ]]; then
  1107                          __docker_images && ret=0
  1108                      else
  1109                          __docker_images && __docker_containers && ret=0
  1110                      fi
  1111                      ;;
  1112              esac
  1113              ;;
  1114          (kill)
  1115              _arguments $(__docker_arguments) \
  1116                  $opts_help \
  1117                  "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \
  1118                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1119              ;;
  1120          (load)
  1121              _arguments $(__docker_arguments) \
  1122                  $opts_help \
  1123                  "($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))(-.)\"" \
  1124                  "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0
  1125              ;;
  1126          (login)
  1127              _arguments $(__docker_arguments) \
  1128                  $opts_help \
  1129                  "($help -p --password)"{-p=,--password=}"[Password]:password: " \
  1130                  "($help -u --user)"{-u=,--user=}"[Username]:username: " \
  1131                  "($help -)1:server: " && ret=0
  1132              ;;
  1133          (logout)
  1134              _arguments $(__docker_arguments) \
  1135                  $opts_help \
  1136                  "($help -)1:server: " && ret=0
  1137              ;;
  1138          (logs)
  1139              _arguments $(__docker_arguments) \
  1140                  $opts_help \
  1141                  "($help)--details[Show extra details provided to logs]" \
  1142                  "($help -f --follow)"{-f,--follow}"[Follow log output]" \
  1143                  "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \
  1144                  "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \
  1145                  "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \
  1146                  "($help -)*:containers:__docker_containers" && ret=0
  1147              ;;
  1148          (network)
  1149              local curcontext="$curcontext" state
  1150              _arguments $(__docker_arguments) \
  1151                  $opts_help \
  1152                  "($help -): :->command" \
  1153                  "($help -)*:: :->option-or-argument" && ret=0
  1154  
  1155              case $state in
  1156                  (command)
  1157                      __docker_network_commands && ret=0
  1158                      ;;
  1159                  (option-or-argument)
  1160                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1161                      __docker_network_subcommand && ret=0
  1162                      ;;
  1163              esac
  1164              ;;
  1165          (pause|unpause)
  1166              _arguments $(__docker_arguments) \
  1167                  $opts_help \
  1168                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1169              ;;
  1170          (port)
  1171              _arguments $(__docker_arguments) \
  1172                  $opts_help \
  1173                  "($help -)1:containers:__docker_runningcontainers" \
  1174                  "($help -)2:port:_ports" && ret=0
  1175              ;;
  1176          (ps)
  1177              _arguments $(__docker_arguments) \
  1178                  $opts_help \
  1179                  "($help -a --all)"{-a,--all}"[Show all containers]" \
  1180                  "($help)--before=[Show only container created before...]:containers:__docker_containers" \
  1181                  "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \
  1182                  "($help)--format[Pretty-print containers using a Go template]:format: " \
  1183                  "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \
  1184                  "($help)-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)" \
  1185                  "($help)--no-trunc[Do not truncate output]" \
  1186                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1187                  "($help -s --size)"{-s,--size}"[Display total file sizes]" \
  1188                  "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0
  1189              ;;
  1190          (pull)
  1191              _arguments $(__docker_arguments) \
  1192                  $opts_help \
  1193                  "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \
  1194                  "($help)--disable-content-trust[Skip image verification]" \
  1195                  "($help -):name:__docker_search" && ret=0
  1196              ;;
  1197          (push)
  1198              _arguments $(__docker_arguments) \
  1199                  $opts_help \
  1200                  "($help)--disable-content-trust[Skip image signing]" \
  1201                  "($help -): :__docker_images" && ret=0
  1202              ;;
  1203          (rename)
  1204              _arguments $(__docker_arguments) \
  1205                  $opts_help \
  1206                  "($help -):old name:__docker_containers" \
  1207                  "($help -):new name: " && ret=0
  1208              ;;
  1209          (restart|stop)
  1210              _arguments $(__docker_arguments) \
  1211                  $opts_help \
  1212                  "($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)" \
  1213                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1214              ;;
  1215          (rm)
  1216              _arguments $(__docker_arguments) \
  1217                  $opts_help \
  1218                  "($help -f --force)"{-f,--force}"[Force removal]" \
  1219                  "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \
  1220                  "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \
  1221                  "($help -)*:containers:->values" && ret=0
  1222              case $state in
  1223                  (values)
  1224                      if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then
  1225                          __docker_containers && ret=0
  1226                      else
  1227                          __docker_stoppedcontainers && ret=0
  1228                      fi
  1229                      ;;
  1230              esac
  1231              ;;
  1232          (rmi)
  1233              _arguments $(__docker_arguments) \
  1234                  $opts_help \
  1235                  "($help -f --force)"{-f,--force}"[Force removal]" \
  1236                  "($help)--no-prune[Do not delete untagged parents]" \
  1237                  "($help -)*: :__docker_images" && ret=0
  1238              ;;
  1239          (run)
  1240              _arguments $(__docker_arguments) \
  1241                  $opts_help \
  1242                  $opts_build_create_run \
  1243                  $opts_build_create_run_update \
  1244                  $opts_create_run \
  1245                  $opts_create_run_update \
  1246                  $opts_attach_exec_run_start \
  1247                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1248                  "($help)--health-cmd=[Command to run to check health]:command: " \
  1249                  "($help)--health-interval=[Time between running the check]:time: " \
  1250                  "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \
  1251                  "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \
  1252                  "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \
  1253                  "($help)--rm[Remove intermediate containers when it exits]" \
  1254                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
  1255                  "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \
  1256                  "($help)--storage-opt=[Set storage driver options per container]:storage options:->storage-opt" \
  1257                  "($help -): :__docker_images" \
  1258                  "($help -):command: _command_names -e" \
  1259                  "($help -)*::arguments: _normal" && ret=0
  1260  
  1261              case $state in
  1262                  (link)
  1263                      if compset -P "*:"; then
  1264                          _wanted alias expl "Alias" compadd -E "" && ret=0
  1265                      else
  1266                          __docker_runningcontainers -qS ":" && ret=0
  1267                      fi
  1268                      ;;
  1269                  (storage-opt)
  1270                      if compset -P "*="; then
  1271                          _message "value" && ret=0
  1272                      else
  1273                          opts=('size')
  1274                          _describe -t filter-opts "storage options" opts -qS "=" && ret=0
  1275                      fi
  1276                      ;;
  1277              esac
  1278  
  1279              ;;
  1280          (save)
  1281              _arguments $(__docker_arguments) \
  1282                  $opts_help \
  1283                  "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \
  1284                  "($help -)*: :__docker_images" && ret=0
  1285              ;;
  1286          (search)
  1287              _arguments $(__docker_arguments) \
  1288                  $opts_help \
  1289                  "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1290                  "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \
  1291                  "($help)--no-trunc[Do not truncate output]" \
  1292                  "($help -):term: " && ret=0
  1293  
  1294              case $state in
  1295                  (filter-options)
  1296                      __docker_complete_search_filters && ret=0
  1297                      ;;
  1298              esac
  1299              ;;
  1300          (start)
  1301              _arguments $(__docker_arguments) \
  1302                  $opts_help \
  1303                  $opts_attach_exec_run_start \
  1304                  "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \
  1305                  "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \
  1306                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
  1307              ;;
  1308          (stats)
  1309              _arguments $(__docker_arguments) \
  1310                  $opts_help \
  1311                  "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \
  1312                  "($help)--no-stream[Disable streaming stats and only pull the first result]" \
  1313                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1314              ;;
  1315          (tag)
  1316              _arguments $(__docker_arguments) \
  1317                  $opts_help \
  1318                  "($help -):source:__docker_images"\
  1319                  "($help -):destination:__docker_repositories_with_tags" && ret=0
  1320              ;;
  1321          (top)
  1322              _arguments $(__docker_arguments) \
  1323                  $opts_help \
  1324                  "($help -)1:containers:__docker_runningcontainers" \
  1325                  "($help -)*:: :->ps-arguments" && ret=0
  1326              case $state in
  1327                  (ps-arguments)
  1328                      _ps && ret=0
  1329                      ;;
  1330              esac
  1331  
  1332              ;;
  1333          (update)
  1334              _arguments $(__docker_arguments) \
  1335                  $opts_help \
  1336                  $opts_create_run_update \
  1337                  $opts_build_create_run_update \
  1338                  "($help -)*: :->values" && ret=0
  1339  
  1340              case $state in
  1341                  (values)
  1342                      if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then
  1343                          __docker_stoppedcontainers && ret=0
  1344                      else
  1345                          __docker_containers && ret=0
  1346                      fi
  1347                      ;;
  1348              esac
  1349              ;;
  1350          (volume)
  1351              local curcontext="$curcontext" state
  1352              _arguments $(__docker_arguments) \
  1353                  $opts_help \
  1354                  "($help -): :->command" \
  1355                  "($help -)*:: :->option-or-argument" && ret=0
  1356  
  1357              case $state in
  1358                  (command)
  1359                      __docker_volume_commands && ret=0
  1360                      ;;
  1361                  (option-or-argument)
  1362                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1363                      __docker_volume_subcommand && ret=0
  1364                      ;;
  1365              esac
  1366              ;;
  1367          (wait)
  1368              _arguments $(__docker_arguments) \
  1369                  $opts_help \
  1370                  "($help -)*:containers:__docker_runningcontainers" && ret=0
  1371              ;;
  1372          (help)
  1373              _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0
  1374              ;;
  1375      esac
  1376  
  1377      return ret
  1378  }
  1379  
  1380  _docker() {
  1381      # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
  1382      # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
  1383      if [[ $service != docker ]]; then
  1384          _call_function - _$service
  1385          return
  1386      fi
  1387  
  1388      local curcontext="$curcontext" state line help="-h --help"
  1389      integer ret=1
  1390      typeset -A opt_args
  1391  
  1392      _arguments $(__docker_arguments) -C \
  1393          "(: -)"{-h,--help}"[Print usage]" \
  1394          "($help)--config[Location of client config files]:path:_directories" \
  1395          "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
  1396          "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
  1397          "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
  1398          "($help)--tls[Use TLS]" \
  1399          "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
  1400          "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
  1401          "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
  1402          "($help)--tlsverify[Use TLS and verify the remote]" \
  1403          "($help)--userland-proxy[Use userland proxy for loopback traffic]" \
  1404          "($help -v --version)"{-v,--version}"[Print version information and quit]" \
  1405          "($help -): :->command" \
  1406          "($help -)*:: :->option-or-argument" && ret=0
  1407  
  1408      local host=${opt_args[-H]}${opt_args[--host]}
  1409      local config=${opt_args[--config]}
  1410      local docker_options="${host:+--host $host} ${config:+--config $config}"
  1411  
  1412      case $state in
  1413          (command)
  1414              __docker_commands && ret=0
  1415              ;;
  1416          (option-or-argument)
  1417              curcontext=${curcontext%:*:*}:docker-$words[1]:
  1418              __docker_subcommand && ret=0
  1419              ;;
  1420      esac
  1421  
  1422      return ret
  1423  }
  1424  
  1425  _dockerd() {
  1426      integer ret=1
  1427      words[1]='daemon'
  1428      __docker_subcommand && ret=0
  1429      return ret
  1430  }
  1431  
  1432  _docker "$@"
  1433  
  1434  # Local Variables:
  1435  # mode: Shell-Script
  1436  # sh-indentation: 4
  1437  # indent-tabs-mode: nil
  1438  # sh-basic-offset: 4
  1439  # End:
  1440  # vim: ft=zsh sw=4 ts=4 et