github.com/goern/docker@v1.9.0-rc1/contrib/completion/zsh/_docker (about)

     1  #compdef docker
     2  #
     3  # zsh completion for docker (http://docker.com)
     4  #
     5  # version:  0.3.0
     6  # github:   https://github.com/felixr/docker-zsh-completion
     7  #
     8  # contributors:
     9  #   - Felix Riedel
    10  #   - Steve Durrheimer
    11  #   - Vincent Bernat
    12  #
    13  # license:
    14  #
    15  # Copyright (c) 2013, Felix Riedel
    16  # All rights reserved.
    17  #
    18  # Redistribution and use in source and binary forms, with or without
    19  # modification, are permitted provided that the following conditions are met:
    20  #     * Redistributions of source code must retain the above copyright
    21  #       notice, this list of conditions and the following disclaimer.
    22  #     * Redistributions in binary form must reproduce the above copyright
    23  #       notice, this list of conditions and the following disclaimer in the
    24  #       documentation and/or other materials provided with the distribution.
    25  #     * Neither the name of the <organization> nor the
    26  #       names of its contributors may be used to endorse or promote products
    27  #       derived from this software without specific prior written permission.
    28  #
    29  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    30  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    31  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    32  # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
    33  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    34  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    35  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    36  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    37  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    38  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    39  #
    40  
    41  __docker_get_containers() {
    42      [[ $PREFIX = -* ]] && return 1
    43      integer ret=1
    44      local kind
    45      declare -a running stopped lines args
    46  
    47      kind=$1
    48      shift
    49      [[ $kind = (stopped|all) ]] && args=($args -a)
    50  
    51      lines=(${(f)"$(_call_program commands docker $docker_options ps --no-trunc $args)"})
    52  
    53      # Parse header line to find columns
    54      local i=1 j=1 k header=${lines[1]}
    55      declare -A begin end
    56      while (( j < ${#header} - 1 )); do
    57          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
    58          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
    59          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
    60          begin[${header[$i,$((j-1))]}]=$i
    61          end[${header[$i,$((j-1))]}]=$k
    62      done
    63      end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line
    64      lines=(${lines[2,-1]})
    65  
    66      # Container ID
    67      local line
    68      local s
    69      for line in $lines; do
    70          s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}"
    71          s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
    72          s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
    73          if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
    74              stopped=($stopped $s)
    75          else
    76              running=($running $s)
    77          fi
    78      done
    79  
    80      # Names: we only display the one without slash. All other names
    81      # are generated and may clutter the completion. However, with
    82      # Swarm, all names may be prefixed by the swarm node name.
    83      local -a names
    84      for line in $lines; do
    85          names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}})
    86          # First step: find a common prefix and strip it (swarm node case)
    87          (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/}
    88          # Second step: only keep the first name without a /
    89          s=${${names:#*/*}[1]}
    90          # If no name, well give up.
    91          (( $#s != 0 )) || continue
    92          s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
    93          s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
    94          if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
    95              stopped=($stopped $s)
    96          else
    97              running=($running $s)
    98          fi
    99      done
   100  
   101      [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0
   102      [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0
   103      return ret
   104  }
   105  
   106  __docker_stoppedcontainers() {
   107      [[ $PREFIX = -* ]] && return 1
   108      __docker_get_containers stopped "$@"
   109  }
   110  
   111  __docker_runningcontainers() {
   112      [[ $PREFIX = -* ]] && return 1
   113      __docker_get_containers running "$@"
   114  }
   115  
   116  __docker_containers() {
   117      [[ $PREFIX = -* ]] && return 1
   118      __docker_get_containers all "$@"
   119  }
   120  
   121  __docker_images() {
   122      [[ $PREFIX = -* ]] && return 1
   123      integer ret=1
   124      declare -a images
   125      images=(${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}})
   126      _describe -t docker-images "images" images && ret=0
   127      __docker_repositories_with_tags && ret=0
   128      return ret
   129  }
   130  
   131  __docker_repositories() {
   132      [[ $PREFIX = -* ]] && return 1
   133      declare -a repos
   134      repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]})
   135      repos=(${repos#<none>})
   136      _describe -t docker-repos "repositories" repos
   137  }
   138  
   139  __docker_repositories_with_tags() {
   140      [[ $PREFIX = -* ]] && return 1
   141      integer ret=1
   142      declare -a repos onlyrepos matched
   143      declare m
   144      repos=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/:::}%% *})
   145      repos=(${${repos%:::<none>}#<none>})
   146      # Check if we have a prefix-match for the current prefix.
   147      onlyrepos=(${repos%::*})
   148      for m in $onlyrepos; do
   149          [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && {
   150              # Yes, complete with tags
   151              repos=(${${repos/:::/:}/:/\\:})
   152              _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0
   153              return ret
   154          }
   155      done
   156      # No, only complete repositories
   157      onlyrepos=(${${repos%:::*}/:/\\:})
   158      _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0
   159  
   160      return ret
   161  }
   162  
   163  __docker_search() {
   164      [[ $PREFIX = -* ]] && return 1
   165      local cache_policy
   166      zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
   167      if [[ -z "$cache_policy" ]]; then
   168          zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
   169      fi
   170  
   171      local searchterm cachename
   172      searchterm="${words[$CURRENT]%/}"
   173      cachename=_docker-search-$searchterm
   174  
   175      local expl
   176      local -a result
   177      if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \
   178          && ! _retrieve_cache ${cachename#_}; then
   179          _message "Searching for ${searchterm}..."
   180          result=(${${${(f)"$(_call_program commands docker $docker_options search $searchterm)"}%% *}[2,-1]})
   181          _store_cache ${cachename#_} result
   182      fi
   183      _wanted dockersearch expl 'available images' compadd -a result
   184  }
   185  
   186  __docker_networks() {
   187      [[ $PREFIX = -* ]] && return 1
   188      integer ret=1
   189      declare -a lines networks
   190  
   191      lines=(${(f)"$(_call_program commands docker $docker_options network ls)"})
   192  
   193      # Parse header line to find columns
   194      local i=1 j=1 k header=${lines[1]}
   195      declare -A begin end
   196      while (( j < ${#header} - 1 )); do
   197          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
   198          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
   199          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
   200          begin[${header[$i,$((j-1))]}]=$i
   201          end[${header[$i,$((j-1))]}]=$k
   202      done
   203      end[${header[$i,$((j-1))]}]=-1
   204      lines=(${lines[2,-1]})
   205  
   206      # Network ID
   207      local line s
   208      for line in $lines; do
   209          s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}"
   210          s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   211          networks=($networks $s)
   212      done
   213  
   214      # Names
   215      for line in $lines; do
   216          s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
   217          s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   218          networks=($networks $s)
   219      done
   220  
   221      _describe -t networks-list "networks" networks && ret=0
   222      return ret
   223  }
   224  
   225  __docker_network_commands() {
   226      local -a _docker_network_subcommands
   227      _docker_network_subcommands=(
   228          "connect:onnects a container to a network"
   229          "create:Creates a new network with a name specified by the user"
   230          "disconnect:Disconnects a container from a network"
   231          "inspect:Displays detailed information on a network"
   232          "ls:Lists all the networks created by the user"
   233          "rm:Deletes a network"
   234      )
   235      _describe -t docker-network-commands "docker network command" _docker_network_subcommands
   236  }
   237  
   238  __docker_network_subcommand() {
   239      local -a _command_args opts_help
   240      local expl help="--help"
   241      integer ret=1
   242  
   243      opts_help=("(: -)--help[Print usage]")
   244  
   245      case "$words[1]" in
   246          (connect|disconnect)
   247              _arguments \
   248                  $opts_help \
   249                  "($help -)1:network:__docker_networks" \
   250                  "($help -)2:containers:__docker_runningcontainers" && ret=0
   251              ;;
   252          (create)
   253              _arguments -A '-*' \
   254                  $opts_help \
   255                  "($help -d --driver)"{-d,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \
   256                  "($help -)1:Network Name: " && ret=0
   257              ;;
   258          (inspect|rm)
   259              _arguments \
   260                  $opts_help \
   261                  "($help -):network:__docker_networks" && ret=0
   262              ;;
   263          (ls)
   264              _arguments \
   265                  $opts_help \
   266                  "($help -l --latest)"{-l,--latest}"[Show the latest network created]" \
   267                  "($help)-n=-[Show n last created networks]:Number of networks: " \
   268                  "($help)--no-trunc[Do not truncate the output]" \
   269                  "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0
   270              ;;
   271          (help)
   272              _arguments ":subcommand:__docker_network_commands" && ret=0
   273              ;;
   274      esac
   275  
   276      return ret
   277  }
   278  
   279  __docker_volumes() {
   280      [[ $PREFIX = -* ]] && return 1
   281      integer ret=1
   282      declare -a lines volumes
   283  
   284      lines=(${(f)"$(_call_program commands docker $docker_options volume ls)"})
   285  
   286      # Parse header line to find columns
   287      local i=1 j=1 k header=${lines[1]}
   288      declare -A begin end
   289      while (( j < ${#header} - 1 )); do
   290          i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
   291          j=$(( i + ${${header[$i,-1]}[(i)  ]} - 1 ))
   292          k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
   293          begin[${header[$i,$((j-1))]}]=$i
   294          end[${header[$i,$((j-1))]}]=$k
   295      done
   296      end[${header[$i,$((j-1))]}]=-1
   297      lines=(${lines[2,-1]})
   298  
   299      # Names
   300      local line s
   301      for line in $lines; do
   302          s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}"
   303          s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
   304          volumes=($volumes $s)
   305      done
   306  
   307      _describe -t volumes-list "volumes" volumes && ret=0
   308      return ret
   309  }
   310  
   311  __docker_volume_commands() {
   312      local -a _docker_volume_subcommands
   313      _docker_volume_subcommands=(
   314          "create:Create a volume"
   315          "inspect:Return low-level information on a volume"
   316          "ls:List volumes"
   317          "rm:Remove a volume"
   318      )
   319      _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands
   320  }
   321  
   322  __docker_volume_subcommand() {
   323      local -a _command_args opts_help
   324      local expl help="--help"
   325      integer ret=1
   326  
   327      opts_help=("(: -)--help[Print usage]")
   328  
   329      case "$words[1]" in
   330          (create)
   331              _arguments \
   332                  $opts_help \
   333                  "($help -d --driver)"{-d,--driver=-}"[Specify volume driver name]:Driver name: " \
   334                  "($help)--name=-[Specify volume name]" \
   335                  "($help -o --opt)*"{-o,--opt=-}"[Set driver specific options]:Driver option: " && ret=0
   336              ;;
   337          (inspect)
   338              _arguments \
   339                  $opts_help \
   340                  "($help -f --format)"{-f,--format=-}"[Format the output using the given go template]:template: " \
   341                  "($help -)1:volume:__docker_volumes" && ret=0
   342              ;;
   343          (ls)
   344              _arguments \
   345                  $opts_help \
   346                  "($help -f --filter)*"{-f,--filter=-}"[Provide filter values (i.e. 'dangling=true')]:filter: " \
   347                  "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0
   348              ;;
   349          (rm)
   350              _arguments \
   351                  $opts_help \
   352                  "($help -):volume:__docker_volumes" && ret=0
   353              ;;
   354          (help)
   355              _arguments ":subcommand:__docker_volume_commands" && ret=0
   356              ;;
   357      esac
   358  
   359      return ret
   360  }
   361  
   362  __docker_caching_policy() {
   363    oldp=( "$1"(Nmh+1) )     # 1 hour
   364    (( $#oldp ))
   365  }
   366  
   367  __docker_commands() {
   368      local cache_policy
   369  
   370      zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
   371      if [[ -z "$cache_policy" ]]; then
   372          zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
   373      fi
   374  
   375      if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \
   376          && ! _retrieve_cache docker_subcommands;
   377      then
   378          local -a lines
   379          lines=(${(f)"$(_call_program commands docker 2>&1)"})
   380          _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I)    *]}]}## #}/ ##/:})
   381          _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command')
   382          _store_cache docker_subcommands _docker_subcommands
   383      fi
   384      _describe -t docker-commands "docker command" _docker_subcommands
   385  }
   386  
   387  __docker_subcommand() {
   388      local -a _command_args opts_help opts_cpumemlimit opts_create
   389      local expl help="--help"
   390      integer ret=1
   391  
   392      opts_help=("(: -)--help[Print usage]")
   393      opts_cpumemlimit=(
   394          "($help -c --cpu-shares)"{-c,--cpu-shares=-}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)"
   395          "($help)--cgroup-parent=-[Parent cgroup for the container]:cgroup: "
   396          "($help)--cpu-period=-[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: "
   397          "($help)--cpu-quota=-[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: "
   398          "($help)--cpuset-cpus=-[CPUs in which to allow execution]:CPUs: "
   399          "($help)--cpuset-mems=-[MEMs in which to allow execution]:MEMs: "
   400          "($help -m --memory)"{-m,--memory=-}"[Memory limit]:Memory limit: "
   401          "($help)--memory-swap=-[Total memory limit with swap]:Memory limit: "
   402          "($help)*--ulimit=-[ulimit options]:ulimit: "
   403      )
   404      opts_create=(
   405          "($help -a --attach)"{-a,--attach=-}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
   406          "($help)*--add-host=-[Add a custom host-to-IP mapping]:host\:ip mapping: "
   407          "($help)--blkio-weight=-[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)"
   408          "($help)*--cap-add=-[Add Linux capabilities]:capability: "
   409          "($help)*--cap-drop=-[Drop Linux capabilities]:capability: "
   410          "($help)--cidfile=-[Write the container ID to the file]:CID file:_files"
   411          "($help)*--device=-[Add a host device to the container]:device:_files"
   412          "($help)*--dns=-[Set custom DNS servers]:DNS server: "
   413          "($help)*--dns-opt=-[Set custom DNS options]:DNS option: "
   414          "($help)*--dns-search=-[Set custom DNS search domains]:DNS domains: "
   415          "($help)*"{-e,--env=-}"[Set environment variables]:environment variable: "
   416          "($help)--entrypoint=-[Overwrite the default entrypoint of the image]:entry point: "
   417          "($help)*--env-file=-[Read environment variables from a file]:environment file:_files"
   418          "($help)*--expose=-[Expose a port from the container without publishing it]: "
   419          "($help)*--group-add=-[Add additional groups to run as]:group:_groups"
   420          "($help -h --hostname)"{-h,--hostname=-}"[Container host name]:hostname:_hosts"
   421          "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]"
   422          "($help)--ipc=-[IPC namespace to use]:IPC namespace: "
   423          "($help)--kernel-memory[Kernel memory limit in bytes.]:Memory limit: "
   424          "($help)*--link=-[Add link to another container]:link:->link"
   425          "($help)*"{-l,--label=-}"[Set meta data on a container]:label: "
   426          "($help)--log-driver=-[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs none)"
   427          "($help)*--log-opt=-[Log driver specific options]:log driver options: "
   428          "($help)*--lxc-conf=-[Add custom lxc options]:lxc options: "
   429          "($help)--mac-address=-[Container MAC address]:MAC address: "
   430          "($help)--name=-[Container name]:name: "
   431          "($help)--net=-[Connect a container to a network]:network mode:(bridge none container host)"
   432          "($help)--oom-kill-disable[Disable OOM Killer]"
   433          "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
   434          "($help)*"{-p,--publish=-}"[Expose a container's port to the host]:port:_ports"
   435          "($help)--pid=-[PID namespace to use]:PID: "
   436          "($help)--privileged[Give extended privileges to this container]"
   437          "($help)--read-only[Mount the container's root filesystem as read only]"
   438          "($help)--restart=-[Restart policy]:restart policy:(no on-failure always)"
   439          "($help)*--security-opt=-[Security options]:security option: "
   440          "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]"
   441          "($help -u --user)"{-u,--user=-}"[Username or UID]:user:_users"
   442          "($help)*-v[Bind mount a volume]:volume: "
   443          "($help)*--volumes-from=-[Mount volumes from the specified container]:volume: "
   444          "($help -w --workdir)"{-w,--workdir=-}"[Working directory inside the container]:directory:_directories"
   445      )
   446  
   447      case "$words[1]" in
   448          (attach)
   449              _arguments \
   450                  $opts_help \
   451                  "($help)--no-stdin[Do not attach stdin]" \
   452                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
   453                  "($help -):containers:__docker_runningcontainers" && ret=0
   454              ;;
   455          (build)
   456              _arguments \
   457                  $opts_help \
   458                  $opts_cpumemlimit \
   459                  "($help -f --file)"{-f,--file=-}"[Name of the Dockerfile]:Dockerfile:_files" \
   460                  "($help)--force-rm[Always remove intermediate containers]" \
   461                  "($help)--no-cache[Do not use cache when building the image]" \
   462                  "($help)--pull[Attempt to pull a newer version of the image]" \
   463                  "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \
   464                  "($help)--rm[Remove intermediate containers after a successful build]" \
   465                  "($help -t --tag)"{-t,--tag=-}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \
   466                  "($help -):path or URL:_directories" && ret=0
   467              ;;
   468          (commit)
   469              _arguments \
   470                  $opts_help \
   471                  "($help -a --author)"{-a,--author=-}"[Author]:author: " \
   472                  "($help -c --change)*"{-c,--change=-}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
   473                  "($help -m --message)"{-m,--message=-}"[Commit message]:message: " \
   474                  "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \
   475                  "($help -):container:__docker_containers" \
   476                  "($help -): :__docker_repositories_with_tags" && ret=0
   477              ;;
   478          (cp)
   479              _arguments \
   480                  $opts_help \
   481                  "($help -)1:container:->container" \
   482                  "($help -)2:hostpath:_files" && ret=0
   483              case $state in
   484                  (container)
   485                      if compset -P "*:"; then
   486                          _files && ret=0
   487                      else
   488                          __docker_containers -qS ":" && ret=0
   489                      fi
   490                      ;;
   491              esac
   492              ;;
   493          (create)
   494              _arguments \
   495                  $opts_help \
   496                  $opts_cpumemlimit \
   497                  $opts_create \
   498                  "($help -): :__docker_images" \
   499                  "($help -):command: _command_names -e" \
   500                  "($help -)*::arguments: _normal" && ret=0
   501  
   502              case $state in
   503                  (link)
   504                      if compset -P "*:"; then
   505                          _wanted alias expl "Alias" compadd -E "" && ret=0
   506                      else
   507                          __docker_runningcontainers -qS ":" && ret=0
   508                      fi
   509                      ;;
   510              esac
   511  
   512              ;;
   513          (daemon)
   514              _arguments \
   515                  $opts_help \
   516                  "($help)--api-cors-header=-[Set CORS headers in the remote API]:CORS headers: " \
   517                  "($help -b --bridge)"{-b,--bridge=-}"[Attach containers to a network bridge]:bridge:_net_interfaces" \
   518                  "($help)--bip=-[Specify network bridge IP]" \
   519                  "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
   520                  "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \
   521                  "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \
   522                  "($help)--cluster-store=-[URL of the distributed storage backend]:Cluster Store:->cluster-store" \
   523                  "($help)--cluster-advertise=-[Address of the daemon instance to advertise]:Instance to advertise (host\:port): " \
   524                  "($help)*--cluster-store-opt[Set cluster options]:Cluster options:->cluster-store-options" \
   525                  "($help)*--dns=-[DNS server to use]:DNS: " \
   526                  "($help)*--dns-search=-[DNS search domains to use]:DNS search: " \
   527                  "($help)*--dns-opt=-[DNS options to use]:DNS option: " \
   528                  "($help)*--default-ulimit=-[Set default ulimit settings for containers]:ulimit: " \
   529                  "($help)--disable-legacy-registry[Do not contact legacy registries]" \
   530                  "($help -e --exec-driver)"{-e,--exec-driver=-}"[Exec driver to use]:driver:(native lxc windows)" \
   531                  "($help)*--exec-opt=-[Set exec driver options]:exec driver options: " \
   532                  "($help)--exec-root=-[Root of the Docker execdriver]:path:_directories" \
   533                  "($help)--fixed-cidr=-[IPv4 subnet for fixed IPs]:IPv4 subnet: " \
   534                  "($help)--fixed-cidr-v6=-[IPv6 subnet for fixed IPs]:IPv6 subnet: " \
   535                  "($help -G --group)"{-G,--group=-}"[Group for the unix socket]:group:_groups" \
   536                  "($help -g --graph)"{-g,--graph=-}"[Root of the Docker runtime]:path:_directories" \
   537                  "($help -H --host)"{-H,--host=-}"[tcp://host:port to bind/connect to]:host: " \
   538                  "($help)--icc[Enable inter-container communication]" \
   539                  "($help)*--insecure-registry=-[Enable insecure registry communication]:registry: " \
   540                  "($help)--ip=-[Default IP when binding container ports]" \
   541                  "($help)--ip-forward[Enable net.ipv4.ip_forward]" \
   542                  "($help)--ip-masq[Enable IP masquerading]" \
   543                  "($help)--iptables[Enable addition of iptables rules]" \
   544                  "($help)--ipv6[Enable IPv6 networking]" \
   545                  "($help -l --log-level)"{-l,--log-level=-}"[Set the logging level]:level:(debug info warn error fatal)" \
   546                  "($help)*--label=-[Set key=value labels to the daemon]:label: " \
   547                  "($help)--log-driver=-[Default driver for container logs]:Logging driver:(json-file syslog journald gelf fluentd awslogs none)" \
   548                  "($help)*--log-opt=-[Log driver specific options]:log driver options: " \
   549                  "($help)--mtu=-[Set the containers network MTU]:mtu:(0 576 1420 1500 9000)" \
   550                  "($help -p --pidfile)"{-p,--pidfile=-}"[Path to use for daemon PID file]:PID file:_files" \
   551                  "($help)*--registry-mirror=-[Preferred Docker registry mirror]:registry mirror: " \
   552                  "($help -s --storage-driver)"{-s,--storage-driver=-}"[Storage driver to use]:driver:(aufs devicemapper btrfs zfs overlay)" \
   553                  "($help)--selinux-enabled[Enable selinux support]" \
   554                  "($help)*--storage-opt=-[Set storage driver options]:storage driver options: " \
   555                  "($help)--tls[Use TLS]" \
   556                  "($help)--tlscacert=-[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
   557                  "($help)--tlscert=-[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
   558                  "($help)--tlskey=-[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
   559                  "($help)--tlsverify[Use TLS and verify the remote]" \
   560                  "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0
   561  
   562              case $state in
   563                  (cluster-store)
   564                      if compset -P '*://'; then
   565                          _message 'host:port' && ret=0
   566                      else
   567                          store=('consul' 'etcd' 'zk')
   568                          _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0
   569                      fi
   570                      ;;
   571                  (cluster-store-options)
   572                      if compset -P '*='; then
   573                          _files && ret=0
   574                      else
   575                          opts=('kv.cacertfile' 'kv.certfile' 'kv.keyfile')
   576                          _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0
   577                      fi
   578                      ;;
   579              esac
   580              ;;
   581          (diff)
   582              _arguments \
   583                  $opts_help \
   584                  "($help -)*:containers:__docker_containers" && ret=0
   585              ;;
   586          (events)
   587              _arguments \
   588                  $opts_help \
   589                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   590                  "($help)--since=-[Events created since this timestamp]:timestamp: " \
   591                  "($help)--until=-[Events created until this timestamp]:timestamp: " && ret=0
   592              ;;
   593          (exec)
   594              local state
   595              _arguments \
   596                  $opts_help \
   597                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
   598                  "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \
   599                  "($help)--privileged[Give extended Linux capabilities to the command]" \
   600                  "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
   601                  "($help -u --user)"{-u,--user=-}"[Username or UID]:user:_users" \
   602                  "($help -):containers:__docker_runningcontainers" \
   603                  "($help -)*::command:->anycommand" && ret=0
   604  
   605              case $state in
   606                  (anycommand)
   607                      shift 1 words
   608                      (( CURRENT-- ))
   609                      _normal && ret=0
   610                      ;;
   611              esac
   612              ;;
   613          (export)
   614              _arguments \
   615                  $opts_help \
   616                  "($help -o --output)"{-o,--output=-}"[Write to a file, instead of stdout]:output file:_files" \
   617                  "($help -)*:containers:__docker_containers" && ret=0
   618              ;;
   619          (history)
   620              _arguments \
   621                  $opts_help \
   622                  "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \
   623                  "($help)--no-trunc[Do not truncate output]" \
   624                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   625                  "($help -)*: :__docker_images" && ret=0
   626              ;;
   627          (images)
   628              _arguments \
   629                  $opts_help \
   630                  "($help -a --all)"{-a,--all}"[Show all images]" \
   631                  "($help)--digest[Show digests]" \
   632                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   633                  "($help)--no-trunc[Do not truncate output]" \
   634                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   635                  "($help -): :__docker_repositories" && ret=0
   636              ;;
   637          (import)
   638              _arguments \
   639                  $opts_help \
   640                  "($help -c --change)*"{-c,--change=-}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
   641                  "($help -):URL:(- http:// file://)" \
   642                  "($help -): :__docker_repositories_with_tags" && ret=0
   643              ;;
   644          (info|version)
   645              _arguments \
   646                  $opts_help && ret=0
   647              ;;
   648          (inspect)
   649              local state
   650              _arguments \
   651                  $opts_help \
   652                  "($help -f --format=-)"{-f,--format=-}"[Format the output using the given go template]:template: " \
   653                  "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \
   654                  "($help)--type=-[Return JSON for specified type]:type:(image container)" \
   655                  "($help -)*: :->values" && ret=0
   656  
   657              case $state in
   658                  (values)
   659                      if [[ ${words[(r)--type=container]} == --type=container ]]; then
   660                          __docker_containers && ret=0
   661                      elif [[ ${words[(r)--type=image]} == --type=image ]]; then
   662                          __docker_images && ret=0
   663                      else
   664                          __docker_images && __docker_containers && ret=0
   665                      fi
   666                      ;;
   667              esac
   668              ;;
   669          (kill)
   670              _arguments \
   671                  $opts_help \
   672                  "($help -s --signal)"{-s,--signal=-}"[Signal to send]:signal:_signals" \
   673                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   674              ;;
   675          (load)
   676              _arguments \
   677                  $opts_help \
   678                  "($help -i --input)"{-i,--input=-}"[Read from tar archive file]:archive file:_files -g "*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)"" && ret=0
   679              ;;
   680          (login)
   681              _arguments \
   682                  $opts_help \
   683                  "($help -e --email)"{-e,--email=-}"[Email]:email: " \
   684                  "($help -p --password)"{-p,--password=-}"[Password]:password: " \
   685                  "($help -u --user)"{-u,--user=-}"[Username]:username: " \
   686                  "($help -)1:server: " && ret=0
   687              ;;
   688          (logout)
   689              _arguments \
   690                  $opts_help \
   691                  "($help -)1:server: " && ret=0
   692              ;;
   693          (logs)
   694              _arguments \
   695                  $opts_help \
   696                  "($help -f --follow)"{-f,--follow}"[Follow log output]" \
   697                  "($help -s --since)"{-s,--since=-}"[Show logs since this timestamp]:timestamp: " \
   698                  "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \
   699                  "($help)--tail=-[Output the last K lines]:lines:(1 10 20 50 all)" \
   700                  "($help -)*:containers:__docker_containers" && ret=0
   701              ;;
   702          (network)
   703              local curcontext="$curcontext" state
   704              _arguments \
   705                  $opts_help \
   706                  "($help -): :->command" \
   707                  "($help -)*:: :->option-or-argument" && ret=0
   708  
   709              case $state in
   710                  (command)
   711                      __docker_network_commands && ret=0
   712                      ;;
   713                  (option-or-argument)
   714                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
   715                      __docker_network_subcommand && ret=0
   716                      ;;
   717              esac
   718              ;;
   719          (pause|unpause)
   720              _arguments \
   721                  $opts_help \
   722                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   723              ;;
   724          (port)
   725              _arguments \
   726                  $opts_help \
   727                  "($help -)1:containers:__docker_runningcontainers" \
   728                  "($help -)2:port:_ports" && ret=0
   729              ;;
   730          (ps)
   731              _arguments \
   732                  $opts_help \
   733                  "($help -a --all)"{-a,--all}"[Show all containers]" \
   734                  "($help)--before=-[Show only container created before...]:containers:__docker_containers" \
   735                  "($help)*"{-f,--filter=-}"[Filter values]:filter: " \
   736                  "($help)--format[Pretty-print containers using a Go template]:format: " \
   737                  "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \
   738                  "($help)-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)" \
   739                  "($help)--no-trunc[Do not truncate output]" \
   740                  "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
   741                  "($help -s --size)"{-s,--size}"[Display total file sizes]" \
   742                  "($help)--since=-[Show only containers created since...]:containers:__docker_containers" && ret=0
   743              ;;
   744          (pull)
   745              _arguments \
   746                  $opts_help \
   747                  "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \
   748                  "($help -):name:__docker_search" && ret=0
   749              ;;
   750          (push)
   751              _arguments \
   752                  $opts_help \
   753                  "($help -): :__docker_images" && ret=0
   754              ;;
   755          (rename)
   756              _arguments \
   757                  $opts_help \
   758                  "($help -):old name:__docker_containers" \
   759                  "($help -):new name: " && ret=0
   760              ;;
   761          (restart|stop)
   762              _arguments \
   763                  $opts_help \
   764                  "($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)" \
   765                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   766              ;;
   767          (rm)
   768              _arguments \
   769                  $opts_help \
   770                  "($help -f --force)"{-f,--force}"[Force removal]" \
   771                  "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \
   772                  "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \
   773                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
   774              ;;
   775          (rmi)
   776              _arguments \
   777                  $opts_help \
   778                  "($help -f --force)"{-f,--force}"[Force removal]" \
   779                  "($help)--no-prune[Do not delete untagged parents]" \
   780                  "($help -)*: :__docker_images" && ret=0
   781              ;;
   782          (run)
   783              _arguments \
   784                  $opts_help \
   785                  $opts_cpumemlimit \
   786                  $opts_create \
   787                  "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
   788                  "($help)--rm[Remove intermediate containers when it exits]" \
   789                  "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
   790                  "($help)--stop-signal=-[Signal to kill a container]:signal:_signals" \
   791                  "($help -): :__docker_images" \
   792                  "($help -):command: _command_names -e" \
   793                  "($help -)*::arguments: _normal" && ret=0
   794  
   795              case $state in
   796                  (link)
   797                      if compset -P "*:"; then
   798                          _wanted alias expl "Alias" compadd -E "" && ret=0
   799                      else
   800                          __docker_runningcontainers -qS ":" && ret=0
   801                      fi
   802                      ;;
   803              esac
   804  
   805              ;;
   806          (save)
   807              _arguments \
   808                  $opts_help \
   809                  "($help -o --output)"{-o,--output=-}"[Write to file]:file:_files" \
   810                  "($help -)*: :__docker_images" && ret=0
   811              ;;
   812          (search)
   813              _arguments \
   814                  $opts_help \
   815                  "($help)--automated[Only show automated builds]" \
   816                  "($help)--no-trunc[Do not truncate output]" \
   817                  "($help -s --stars)"{-s,--stars=-}"[Only display with at least X stars]:stars:(0 10 100 1000)" \
   818                  "($help -):term: " && ret=0
   819              ;;
   820          (start)
   821              _arguments \
   822                  $opts_help \
   823                  "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \
   824                  "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \
   825                  "($help -)*:containers:__docker_stoppedcontainers" && ret=0
   826              ;;
   827          (stats)
   828              _arguments \
   829                  $opts_help \
   830                  "($help)--no-stream[Disable streaming stats and only pull the first result]" \
   831                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   832              ;;
   833          (tag)
   834              _arguments \
   835                  $opts_help \
   836                  "($help -f --force)"{-f,--force}"[force]"\
   837                  "($help -):source:__docker_images"\
   838                  "($help -):destination:__docker_repositories_with_tags" && ret=0
   839              ;;
   840          (top)
   841              _arguments \
   842                  $opts_help \
   843                  "($help -)1:containers:__docker_runningcontainers" \
   844                  "($help -)*:: :->ps-arguments" && ret=0
   845              case $state in
   846                  (ps-arguments)
   847                      _ps && ret=0
   848                      ;;
   849              esac
   850  
   851              ;;
   852          (volume)
   853              local curcontext="$curcontext" state
   854              _arguments \
   855                  $opts_help \
   856                  "($help -): :->command" \
   857                  "($help -)*:: :->option-or-argument" && ret=0
   858  
   859              case $state in
   860                  (command)
   861                      __docker_volume_commands && ret=0
   862                      ;;
   863                  (option-or-argument)
   864                      curcontext=${curcontext%:*:*}:docker-${words[-1]}:
   865                      __docker_volume_subcommand && ret=0
   866                      ;;
   867              esac
   868              ;;
   869          (wait)
   870              _arguments \
   871                  $opts_help \
   872                  "($help -)*:containers:__docker_runningcontainers" && ret=0
   873              ;;
   874          (help)
   875              _arguments ":subcommand:__docker_commands" && ret=0
   876              ;;
   877      esac
   878  
   879      return ret
   880  }
   881  
   882  _docker() {
   883      # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
   884      # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
   885      if [[ $service != docker ]]; then
   886          _call_function - _$service
   887          return
   888      fi
   889  
   890      local curcontext="$curcontext" state line help="-h --help"
   891      integer ret=1
   892      typeset -A opt_args
   893  
   894      _arguments -C \
   895          "(: -)"{-h,--help}"[Print usage]" \
   896          "($help)--config[Location of client config files]:path:_directories" \
   897          "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
   898          "($help -H --host)"{-H,--host=-}"[tcp://host:port to bind/connect to]:host: " \
   899          "($help -l --log-level)"{-l,--log-level=-}"[Set the logging level]:level:(debug info warn error fatal)" \
   900          "($help)--tls[Use TLS]" \
   901          "($help)--tlscacert=-[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
   902          "($help)--tlscert=-[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
   903          "($help)--tlskey=-[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
   904          "($help)--tlsverify[Use TLS and verify the remote]" \
   905          "($help)--userland-proxy[Use userland proxy for loopback traffic]" \
   906          "($help -v --version)"{-v,--version}"[Print version information and quit]" \
   907          "($help -): :->command" \
   908          "($help -)*:: :->option-or-argument" && ret=0
   909  
   910      local host=${opt_args[-H]}${opt_args[--host]}
   911      local config=${opt_args[--config]}
   912      local docker_options="${host:+--host $host} ${config:+--config $config}"
   913  
   914      case $state in
   915          (command)
   916              __docker_commands && ret=0
   917              ;;
   918          (option-or-argument)
   919              curcontext=${curcontext%:*:*}:docker-$words[1]:
   920              __docker_subcommand && ret=0
   921              ;;
   922      esac
   923  
   924      return ret
   925  }
   926  
   927  _docker "$@"
   928  
   929  # Local Variables:
   930  # mode: Shell-Script
   931  # sh-indentation: 4
   932  # indent-tabs-mode: nil
   933  # sh-basic-offset: 4
   934  # End:
   935  # vim: ft=zsh sw=4 ts=4 et