my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3143 lines
128 KiB

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