_docker 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166
  1. #compdef docker dockerd
  2. #
  3. # zsh completion for docker (http://docker.com)
  4. #
  5. # version: 0.3.0
  6. # github: https://github.com/felixr/docker-zsh-completion
  7. #
  8. # contributors:
  9. # - Felix Riedel
  10. # - Steve Durrheimer
  11. # - Vincent Bernat
  12. #
  13. # license:
  14. #
  15. # Copyright (c) 2013, Felix Riedel
  16. # All rights reserved.
  17. #
  18. # Redistribution and use in source and binary forms, with or without
  19. # modification, are permitted provided that the following conditions are met:
  20. # * Redistributions of source code must retain the above copyright
  21. # notice, this list of conditions and the following disclaimer.
  22. # * Redistributions in binary form must reproduce the above copyright
  23. # notice, this list of conditions and the following disclaimer in the
  24. # documentation and/or other materials provided with the distribution.
  25. # * Neither the name of the <organization> nor the
  26. # names of its contributors may be used to endorse or promote products
  27. # derived from this software without specific prior written permission.
  28. #
  29. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  30. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32. # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  33. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  34. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  36. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. #
  40. # Short-option stacking can be enabled with:
  41. # zstyle ':completion:*:*:docker:*' option-stacking yes
  42. # zstyle ':completion:*:*:docker-*:*' option-stacking yes
  43. __docker_arguments() {
  44. if zstyle -t ":completion:${curcontext}:" option-stacking; then
  45. print -- -s
  46. fi
  47. }
  48. __docker_get_containers() {
  49. [[ $PREFIX = -* ]] && return 1
  50. integer ret=1
  51. local kind type line s
  52. declare -a running stopped lines args names
  53. kind=$1; shift
  54. type=$1; shift
  55. [[ $kind = (stopped|all) ]] && args=($args -a)
  56. lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}})
  57. # Parse header line to find columns
  58. local i=1 j=1 k header=${lines[1]}
  59. declare -A begin end
  60. while (( j < ${#header} - 1 )); do
  61. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  62. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  63. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  64. begin[${header[$i,$((j-1))]}]=$i
  65. end[${header[$i,$((j-1))]}]=$k
  66. done
  67. end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line
  68. lines=(${lines[2,-1]})
  69. # Container ID
  70. if [[ $type = (ids|all) ]]; then
  71. for line in $lines; do
  72. s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}"
  73. s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
  74. s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
  75. if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
  76. stopped=($stopped $s)
  77. else
  78. running=($running $s)
  79. fi
  80. done
  81. fi
  82. # Names: we only display the one without slash. All other names
  83. # are generated and may clutter the completion. However, with
  84. # Swarm, all names may be prefixed by the swarm node name.
  85. if [[ $type = (names|all) ]]; then
  86. for line in $lines; do
  87. names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}})
  88. # First step: find a common prefix and strip it (swarm node case)
  89. (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/}
  90. # Second step: only keep the first name without a /
  91. s=${${names:#*/*}[1]}
  92. # If no name, well give up.
  93. (( $#s != 0 )) || continue
  94. s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
  95. s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
  96. if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
  97. stopped=($stopped $s)
  98. else
  99. running=($running $s)
  100. fi
  101. done
  102. fi
  103. [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0
  104. [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0
  105. return ret
  106. }
  107. __docker_stoppedcontainers() {
  108. [[ $PREFIX = -* ]] && return 1
  109. __docker_get_containers stopped all "$@"
  110. }
  111. __docker_runningcontainers() {
  112. [[ $PREFIX = -* ]] && return 1
  113. __docker_get_containers running all "$@"
  114. }
  115. __docker_containers() {
  116. [[ $PREFIX = -* ]] && return 1
  117. __docker_get_containers all all "$@"
  118. }
  119. __docker_containers_ids() {
  120. [[ $PREFIX = -* ]] && return 1
  121. __docker_get_containers all ids "$@"
  122. }
  123. __docker_containers_names() {
  124. [[ $PREFIX = -* ]] && return 1
  125. __docker_get_containers all names "$@"
  126. }
  127. __docker_complete_info_plugins() {
  128. [[ $PREFIX = -* ]] && return 1
  129. integer ret=1
  130. emulate -L zsh
  131. setopt extendedglob
  132. local -a plugins
  133. plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: })
  134. _describe -t plugins "$1 plugins" plugins && ret=0
  135. return ret
  136. }
  137. __docker_images() {
  138. [[ $PREFIX = -* ]] && return 1
  139. integer ret=1
  140. declare -a images
  141. images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}})
  142. _describe -t docker-images "images" images && ret=0
  143. __docker_repositories_with_tags && ret=0
  144. return ret
  145. }
  146. __docker_repositories() {
  147. [[ $PREFIX = -* ]] && return 1
  148. declare -a repos
  149. repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]})
  150. repos=(${repos#<none>})
  151. _describe -t docker-repos "repositories" repos
  152. }
  153. __docker_repositories_with_tags() {
  154. [[ $PREFIX = -* ]] && return 1
  155. integer ret=1
  156. declare -a repos onlyrepos matched
  157. declare m
  158. repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *})
  159. repos=(${${repos%:::<none>}#<none>})
  160. # Check if we have a prefix-match for the current prefix.
  161. onlyrepos=(${repos%::*})
  162. for m in $onlyrepos; do
  163. [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && {
  164. # Yes, complete with tags
  165. repos=(${${repos/:::/:}/:/\\:})
  166. _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0
  167. return ret
  168. }
  169. done
  170. # No, only complete repositories
  171. onlyrepos=(${${repos%:::*}/:/\\:})
  172. _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0
  173. return ret
  174. }
  175. __docker_search() {
  176. [[ $PREFIX = -* ]] && return 1
  177. local cache_policy
  178. zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  179. if [[ -z "$cache_policy" ]]; then
  180. zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
  181. fi
  182. local searchterm cachename
  183. searchterm="${words[$CURRENT]%/}"
  184. cachename=_docker-search-$searchterm
  185. local expl
  186. local -a result
  187. if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \
  188. && ! _retrieve_cache ${cachename#_}; then
  189. _message "Searching for ${searchterm}..."
  190. result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]})
  191. _store_cache ${cachename#_} result
  192. fi
  193. _wanted dockersearch expl 'available images' compadd -a result
  194. }
  195. __docker_get_log_options() {
  196. [[ $PREFIX = -* ]] && return 1
  197. integer ret=1
  198. local log_driver=${opt_args[--log-driver]:-"all"}
  199. local -a awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options
  200. awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream")
  201. fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag")
  202. gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels")
  203. gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag")
  204. journald_options=("env" "labels" "tag")
  205. json_file_options=("env" "labels" "max-file" "max-size")
  206. logentries_options=("logentries-token")
  207. syslog_options=("env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag")
  208. splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag")
  209. [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0
  210. [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0
  211. [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0
  212. [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0
  213. [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0
  214. [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0
  215. [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0
  216. [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0
  217. [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0
  218. return ret
  219. }
  220. __docker_log_drivers() {
  221. [[ $PREFIX = -* ]] && return 1
  222. integer ret=1
  223. drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog)
  224. _describe -t log-drivers "log drivers" drivers && ret=0
  225. return ret
  226. }
  227. __docker_log_options() {
  228. [[ $PREFIX = -* ]] && return 1
  229. integer ret=1
  230. if compset -P '*='; then
  231. case "${${words[-1]%=*}#*=}" in
  232. (syslog-format)
  233. syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro')
  234. _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0
  235. ;;
  236. *)
  237. _message 'value' && ret=0
  238. ;;
  239. esac
  240. else
  241. __docker_get_log_options -qS "=" && ret=0
  242. fi
  243. return ret
  244. }
  245. __docker_complete_detach_keys() {
  246. [[ $PREFIX = -* ]] && return 1
  247. integer ret=1
  248. compset -P "*,"
  249. keys=(${:-{a-z}})
  250. ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}})
  251. _describe -t detach_keys "[a-z]" keys -qS "," && ret=0
  252. _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0
  253. }
  254. __docker_complete_pid() {
  255. [[ $PREFIX = -* ]] && return 1
  256. integer ret=1
  257. local -a opts vopts
  258. opts=('host')
  259. vopts=('container')
  260. if compset -P '*:'; then
  261. case "${${words[-1]%:*}#*=}" in
  262. (container)
  263. __docker_runningcontainers && ret=0
  264. ;;
  265. *)
  266. _message 'value' && ret=0
  267. ;;
  268. esac
  269. else
  270. _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0
  271. _describe -t pid-opts "PID Options" opts && ret=0
  272. fi
  273. return ret
  274. }
  275. __docker_complete_runtimes() {
  276. [[ $PREFIX = -* ]] && return 1
  277. integer ret=1
  278. emulate -L zsh
  279. setopt extendedglob
  280. local -a runtimes_opts
  281. runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}})
  282. _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0
  283. }
  284. __docker_complete_ps_filters() {
  285. [[ $PREFIX = -* ]] && return 1
  286. integer ret=1
  287. if compset -P '*='; then
  288. case "${${words[-1]%=*}#*=}" in
  289. (ancestor)
  290. __docker_images && ret=0
  291. ;;
  292. (before|since)
  293. __docker_containers && ret=0
  294. ;;
  295. (id)
  296. __docker_containers_ids && ret=0
  297. ;;
  298. (is-task)
  299. _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
  300. ;;
  301. (name)
  302. __docker_containers_names && ret=0
  303. ;;
  304. (network)
  305. __docker_networks && ret=0
  306. ;;
  307. (status)
  308. status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing')
  309. _describe -t status-filter-opts "Status Filter Options" status_opts && ret=0
  310. ;;
  311. (volume)
  312. __docker_volumes && ret=0
  313. ;;
  314. *)
  315. _message 'value' && ret=0
  316. ;;
  317. esac
  318. else
  319. opts=('ancestor' 'before' 'exited' 'id' 'label' 'name' 'network' 'since' 'status' 'volume')
  320. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  321. fi
  322. return ret
  323. }
  324. __docker_complete_search_filters() {
  325. [[ $PREFIX = -* ]] && return 1
  326. integer ret=1
  327. declare -a boolean_opts opts
  328. boolean_opts=('true' 'false')
  329. opts=('is-automated' 'is-official' 'stars')
  330. if compset -P '*='; then
  331. case "${${words[-1]%=*}#*=}" in
  332. (is-automated|is-official)
  333. _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
  334. ;;
  335. *)
  336. _message 'value' && ret=0
  337. ;;
  338. esac
  339. else
  340. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  341. fi
  342. return ret
  343. }
  344. __docker_complete_images_filters() {
  345. [[ $PREFIX = -* ]] && return 1
  346. integer ret=1
  347. declare -a boolean_opts opts
  348. boolean_opts=('true' 'false')
  349. opts=('before' 'dangling' 'label' 'since')
  350. if compset -P '*='; then
  351. case "${${words[-1]%=*}#*=}" in
  352. (before|since)
  353. __docker_images && ret=0
  354. ;;
  355. (dangling)
  356. _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
  357. ;;
  358. *)
  359. _message 'value' && ret=0
  360. ;;
  361. esac
  362. else
  363. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  364. fi
  365. return ret
  366. }
  367. __docker_complete_events_filter() {
  368. [[ $PREFIX = -* ]] && return 1
  369. integer ret=1
  370. declare -a opts
  371. opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume')
  372. if compset -P '*='; then
  373. case "${${words[-1]%=*}#*=}" in
  374. (container)
  375. __docker_containers && ret=0
  376. ;;
  377. (daemon)
  378. emulate -L zsh
  379. setopt extendedglob
  380. local -a daemon_opts
  381. daemon_opts=(
  382. ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}}
  383. ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:}
  384. )
  385. _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0
  386. ;;
  387. (event)
  388. local -a event_opts
  389. event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach'
  390. 'exec_start' 'export' 'health_status' 'import' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start'
  391. 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update')
  392. _describe -t event-filter-opts "event filter options" event_opts && ret=0
  393. ;;
  394. (image)
  395. __docker_images && ret=0
  396. ;;
  397. (network)
  398. __docker_networks && ret=0
  399. ;;
  400. (type)
  401. local -a type_opts
  402. type_opts=('container' 'daemon' 'image' 'network' 'volume')
  403. _describe -t type-filter-opts "type filter options" type_opts && ret=0
  404. ;;
  405. (volume)
  406. __docker_volumes && ret=0
  407. ;;
  408. *)
  409. _message 'value' && ret=0
  410. ;;
  411. esac
  412. else
  413. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  414. fi
  415. return ret
  416. }
  417. # BO network
  418. __docker_network_complete_ls_filters() {
  419. [[ $PREFIX = -* ]] && return 1
  420. integer ret=1
  421. if compset -P '*='; then
  422. case "${${words[-1]%=*}#*=}" in
  423. (driver)
  424. __docker_complete_info_plugins Network && ret=0
  425. ;;
  426. (id)
  427. __docker_networks_ids && ret=0
  428. ;;
  429. (name)
  430. __docker_networks_names && ret=0
  431. ;;
  432. (type)
  433. type_opts=('builtin' 'custom')
  434. _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0
  435. ;;
  436. *)
  437. _message 'value' && ret=0
  438. ;;
  439. esac
  440. else
  441. opts=('driver' 'id' 'label' 'name' 'type')
  442. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  443. fi
  444. return ret
  445. }
  446. __docker_get_networks() {
  447. [[ $PREFIX = -* ]] && return 1
  448. integer ret=1
  449. local line s
  450. declare -a lines networks
  451. type=$1; shift
  452. lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}})
  453. # Parse header line to find columns
  454. local i=1 j=1 k header=${lines[1]}
  455. declare -A begin end
  456. while (( j < ${#header} - 1 )); do
  457. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  458. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  459. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  460. begin[${header[$i,$((j-1))]}]=$i
  461. end[${header[$i,$((j-1))]}]=$k
  462. done
  463. end[${header[$i,$((j-1))]}]=-1
  464. lines=(${lines[2,-1]})
  465. # Network ID
  466. if [[ $type = (ids|all) ]]; then
  467. for line in $lines; do
  468. s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}"
  469. s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
  470. networks=($networks $s)
  471. done
  472. fi
  473. # Names
  474. if [[ $type = (names|all) ]]; then
  475. for line in $lines; do
  476. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  477. s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
  478. networks=($networks $s)
  479. done
  480. fi
  481. _describe -t networks-list "networks" networks "$@" && ret=0
  482. return ret
  483. }
  484. __docker_networks() {
  485. [[ $PREFIX = -* ]] && return 1
  486. __docker_get_networks all "$@"
  487. }
  488. __docker_networks_ids() {
  489. [[ $PREFIX = -* ]] && return 1
  490. __docker_get_networks ids "$@"
  491. }
  492. __docker_networks_names() {
  493. [[ $PREFIX = -* ]] && return 1
  494. __docker_get_networks names "$@"
  495. }
  496. __docker_network_commands() {
  497. local -a _docker_network_subcommands
  498. _docker_network_subcommands=(
  499. "connect:Connect a container to a network"
  500. "create:Creates a new network with a name specified by the user"
  501. "disconnect:Disconnects a container from a network"
  502. "inspect:Displays detailed information on a network"
  503. "ls:Lists all the networks created by the user"
  504. "rm:Deletes one or more networks"
  505. )
  506. _describe -t docker-network-commands "docker network command" _docker_network_subcommands
  507. }
  508. __docker_network_subcommand() {
  509. local -a _command_args opts_help
  510. local expl help="--help"
  511. integer ret=1
  512. opts_help=("(: -)--help[Print usage]")
  513. case "$words[1]" in
  514. (connect)
  515. _arguments $(__docker_arguments) \
  516. $opts_help \
  517. "($help)*--alias=[Add network-scoped alias for the container]:alias: " \
  518. "($help)--ip=[Container IPv4 address]:IPv4: " \
  519. "($help)--ip6=[Container IPv6 address]:IPv6: " \
  520. "($help)*--link=[Add a link to another container]:link:->link" \
  521. "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \
  522. "($help -)1:network:__docker_networks" \
  523. "($help -)2:containers:__docker_containers" && ret=0
  524. case $state in
  525. (link)
  526. if compset -P "*:"; then
  527. _wanted alias expl "Alias" compadd -E "" && ret=0
  528. else
  529. __docker_runningcontainers -qS ":" && ret=0
  530. fi
  531. ;;
  532. esac
  533. ;;
  534. (create)
  535. _arguments $(__docker_arguments) -A '-*' \
  536. $opts_help \
  537. "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \
  538. "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \
  539. "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \
  540. "($help)--internal[Restricts external access to the network]" \
  541. "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \
  542. "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \
  543. "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \
  544. "($help)--ipv6[Enable IPv6 networking]" \
  545. "($help)*--label=[Set metadata on a network]:label=value: " \
  546. "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \
  547. "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \
  548. "($help -)1:Network Name: " && ret=0
  549. ;;
  550. (disconnect)
  551. _arguments $(__docker_arguments) \
  552. $opts_help \
  553. "($help -)1:network:__docker_networks" \
  554. "($help -)2:containers:__docker_containers" && ret=0
  555. ;;
  556. (inspect)
  557. _arguments $(__docker_arguments) \
  558. $opts_help \
  559. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  560. "($help -)*:network:__docker_networks" && ret=0
  561. ;;
  562. (ls)
  563. _arguments $(__docker_arguments) \
  564. $opts_help \
  565. "($help)--no-trunc[Do not truncate the output]" \
  566. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  567. "($help)--format=[Pretty-print networks using a Go template]:template: " \
  568. "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0
  569. case $state in
  570. (filter-options)
  571. __docker_network_complete_ls_filters && ret=0
  572. ;;
  573. esac
  574. ;;
  575. (rm)
  576. _arguments $(__docker_arguments) \
  577. $opts_help \
  578. "($help -)*:network:__docker_networks" && ret=0
  579. ;;
  580. (help)
  581. _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
  582. ;;
  583. esac
  584. return ret
  585. }
  586. # EO network
  587. # BO node
  588. __docker_node_complete_ls_filters() {
  589. [[ $PREFIX = -* ]] && return 1
  590. integer ret=1
  591. if compset -P '*='; then
  592. case "${${words[-1]%=*}#*=}" in
  593. (id)
  594. __docker_complete_nodes_ids && ret=0
  595. ;;
  596. (membership)
  597. membership_opts=('accepted' 'pending' 'rejected')
  598. _describe -t membership-opts "membership options" membership_opts && ret=0
  599. ;;
  600. (name)
  601. __docker_complete_nodes_names && ret=0
  602. ;;
  603. (role)
  604. role_opts=('manager' 'worker')
  605. _describe -t role-opts "role options" role_opts && ret=0
  606. ;;
  607. *)
  608. _message 'value' && ret=0
  609. ;;
  610. esac
  611. else
  612. opts=('id' 'label' 'membership' 'name' 'role')
  613. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  614. fi
  615. return ret
  616. }
  617. __docker_node_complete_ps_filters() {
  618. [[ $PREFIX = -* ]] && return 1
  619. integer ret=1
  620. if compset -P '*='; then
  621. case "${${words[-1]%=*}#*=}" in
  622. (desired-state)
  623. state_opts=('accepted' 'running')
  624. _describe -t state-opts "desired state options" state_opts && ret=0
  625. ;;
  626. *)
  627. _message 'value' && ret=0
  628. ;;
  629. esac
  630. else
  631. opts=('desired-state' 'id' 'label' 'name')
  632. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  633. fi
  634. return ret
  635. }
  636. __docker_nodes() {
  637. [[ $PREFIX = -* ]] && return 1
  638. integer ret=1
  639. local line s
  640. declare -a lines nodes args
  641. type=$1; shift
  642. filter=$1; shift
  643. [[ $filter != "none" ]] && args=("-f $filter")
  644. lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}})
  645. # Parse header line to find columns
  646. local i=1 j=1 k header=${lines[1]}
  647. declare -A begin end
  648. while (( j < ${#header} - 1 )); do
  649. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  650. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  651. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  652. begin[${header[$i,$((j-1))]}]=$i
  653. end[${header[$i,$((j-1))]}]=$k
  654. done
  655. end[${header[$i,$((j-1))]}]=-1
  656. lines=(${lines[2,-1]})
  657. # Node ID
  658. if [[ $type = (ids|all) ]]; then
  659. for line in $lines; do
  660. s="${line[${begin[ID]},${end[ID]}]%% ##}"
  661. nodes=($nodes $s)
  662. done
  663. fi
  664. # Names
  665. if [[ $type = (names|all) ]]; then
  666. for line in $lines; do
  667. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  668. nodes=($nodes $s)
  669. done
  670. fi
  671. _describe -t nodes-list "nodes" nodes "$@" && ret=0
  672. return ret
  673. }
  674. __docker_complete_nodes() {
  675. [[ $PREFIX = -* ]] && return 1
  676. __docker_nodes all none "$@"
  677. }
  678. __docker_complete_nodes_ids() {
  679. [[ $PREFIX = -* ]] && return 1
  680. __docker_nodes ids none "$@"
  681. }
  682. __docker_complete_nodes_names() {
  683. [[ $PREFIX = -* ]] && return 1
  684. __docker_nodes names none "$@"
  685. }
  686. __docker_complete_pending_nodes() {
  687. [[ $PREFIX = -* ]] && return 1
  688. __docker_nodes all "membership=pending" "$@"
  689. }
  690. __docker_complete_manager_nodes() {
  691. [[ $PREFIX = -* ]] && return 1
  692. __docker_nodes all "role=manager" "$@"
  693. }
  694. __docker_complete_worker_nodes() {
  695. [[ $PREFIX = -* ]] && return 1
  696. __docker_nodes all "role=worker" "$@"
  697. }
  698. __docker_node_commands() {
  699. local -a _docker_node_subcommands
  700. _docker_node_subcommands=(
  701. "demote:Demote a node as manager in the swarm"
  702. "inspect:Display detailed information on one or more nodes"
  703. "ls:List nodes in the swarm"
  704. "promote:Promote a node as manager in the swarm"
  705. "rm:Remove one or more nodes from the swarm"
  706. "ps:List tasks running on one or more nodes, defaults to current node"
  707. "update:Update a node"
  708. )
  709. _describe -t docker-node-commands "docker node command" _docker_node_subcommands
  710. }
  711. __docker_node_subcommand() {
  712. local -a _command_args opts_help
  713. local expl help="--help"
  714. integer ret=1
  715. opts_help=("(: -)--help[Print usage]")
  716. case "$words[1]" in
  717. (rm|remove)
  718. _arguments $(__docker_arguments) \
  719. $opts_help \
  720. "($help)--force[Force remove an active node]" \
  721. "($help -)*:node:__docker_complete_pending_nodes" && ret=0
  722. ;;
  723. (demote)
  724. _arguments $(__docker_arguments) \
  725. $opts_help \
  726. "($help -)*:node:__docker_complete_manager_nodes" && ret=0
  727. ;;
  728. (inspect)
  729. _arguments $(__docker_arguments) \
  730. $opts_help \
  731. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  732. "($help)--pretty[Print the information in a human friendly format]" \
  733. "($help -)*:node:__docker_complete_nodes" && ret=0
  734. ;;
  735. (ls|list)
  736. _arguments $(__docker_arguments) \
  737. $opts_help \
  738. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  739. "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0
  740. case $state in
  741. (filter-options)
  742. __docker_node_complete_ls_filters && ret=0
  743. ;;
  744. esac
  745. ;;
  746. (promote)
  747. _arguments $(__docker_arguments) \
  748. $opts_help \
  749. "($help -)*:node:__docker_complete_worker_nodes" && ret=0
  750. ;;
  751. (ps)
  752. _arguments $(__docker_arguments) \
  753. $opts_help \
  754. "($help -a --all)"{-a,--all}"[Display all instances]" \
  755. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  756. "($help)--no-resolve[Do not map IDs to Names]" \
  757. "($help)--no-trunc[Do not truncate output]" \
  758. "($help -)*:node:__docker_complete_nodes" && ret=0
  759. case $state in
  760. (filter-options)
  761. __docker_node_complete_ps_filters && ret=0
  762. ;;
  763. esac
  764. ;;
  765. (update)
  766. _arguments $(__docker_arguments) \
  767. $opts_help \
  768. "($help)--availability=[Availability of the node]:availability:(active pause drain)" \
  769. "($help)*--label-add=[Add or update a node label]:key=value: " \
  770. "($help)*--label-rm=[Remove a node label if exists]:label: " \
  771. "($help)--role=[Role of the node]:role:(manager worker)" \
  772. "($help -)1:node:__docker_complete_nodes" && ret=0
  773. ;;
  774. (help)
  775. _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0
  776. ;;
  777. esac
  778. return ret
  779. }
  780. # EO node
  781. # BO plugin
  782. __docker_complete_plugins() {
  783. [[ $PREFIX = -* ]] && return 1
  784. integer ret=1
  785. local line s
  786. declare -a lines plugins
  787. lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls)"$'\n'}})
  788. # Parse header line to find columns
  789. local i=1 j=1 k header=${lines[1]}
  790. declare -A begin end
  791. while (( j < ${#header} - 1 )); do
  792. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  793. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  794. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  795. begin[${header[$i,$((j-1))]}]=$i
  796. end[${header[$i,$((j-1))]}]=$k
  797. done
  798. end[${header[$i,$((j-1))]}]=-1
  799. lines=(${lines[2,-1]})
  800. # Name
  801. for line in $lines; do
  802. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  803. s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}"
  804. plugins=($plugins $s)
  805. done
  806. _describe -t plugins-list "plugins" plugins "$@" && ret=0
  807. return ret
  808. }
  809. __docker_plugin_commands() {
  810. local -a _docker_plugin_subcommands
  811. _docker_plugin_subcommands=(
  812. "disable:Disable a plugin"
  813. "enable:Enable a plugin"
  814. "inspect:Return low-level information about a plugin"
  815. "install:Install a plugin"
  816. "ls:List plugins"
  817. "push:Push a plugin"
  818. "rm:Remove a plugin"
  819. "set:Change settings for a plugin"
  820. )
  821. _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands
  822. }
  823. __docker_plugin_subcommand() {
  824. local -a _command_args opts_help
  825. local expl help="--help"
  826. integer ret=1
  827. opts_help=("(: -)--help[Print usage]")
  828. case "$words[1]" in
  829. (disable|enable|inspect|install|ls|push|rm)
  830. _arguments $(__docker_arguments) \
  831. $opts_help \
  832. "($help -)1:plugin:__docker_complete_plugins" && ret=0
  833. ;;
  834. (set)
  835. _arguments $(__docker_arguments) \
  836. $opts_help \
  837. "($help -)1:plugin:__docker_complete_plugins" \
  838. "($help-)*:key=value: " && ret=0
  839. ;;
  840. (help)
  841. _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0
  842. ;;
  843. esac
  844. return ret
  845. }
  846. # EO plugin
  847. # BO service
  848. __docker_service_complete_ls_filters() {
  849. [[ $PREFIX = -* ]] && return 1
  850. integer ret=1
  851. if compset -P '*='; then
  852. case "${${words[-1]%=*}#*=}" in
  853. (id)
  854. __docker_complete_services_ids && ret=0
  855. ;;
  856. (name)
  857. __docker_complete_services_names && ret=0
  858. ;;
  859. *)
  860. _message 'value' && ret=0
  861. ;;
  862. esac
  863. else
  864. opts=('id' 'label' 'name')
  865. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  866. fi
  867. return ret
  868. }
  869. __docker_service_complete_ps_filters() {
  870. [[ $PREFIX = -* ]] && return 1
  871. integer ret=1
  872. if compset -P '*='; then
  873. case "${${words[-1]%=*}#*=}" in
  874. (desired-state)
  875. state_opts=('accepted' 'running')
  876. _describe -t state-opts "desired state options" state_opts && ret=0
  877. ;;
  878. *)
  879. _message 'value' && ret=0
  880. ;;
  881. esac
  882. else
  883. opts=('desired-state' 'id' 'label' 'name')
  884. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  885. fi
  886. return ret
  887. }
  888. __docker_services() {
  889. [[ $PREFIX = -* ]] && return 1
  890. integer ret=1
  891. local line s
  892. declare -a lines services
  893. type=$1; shift
  894. lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}})
  895. # Parse header line to find columns
  896. local i=1 j=1 k header=${lines[1]}
  897. declare -A begin end
  898. while (( j < ${#header} - 1 )); do
  899. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  900. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  901. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  902. begin[${header[$i,$((j-1))]}]=$i
  903. end[${header[$i,$((j-1))]}]=$k
  904. done
  905. end[${header[$i,$((j-1))]}]=-1
  906. lines=(${lines[2,-1]})
  907. # Service ID
  908. if [[ $type = (ids|all) ]]; then
  909. for line in $lines; do
  910. s="${line[${begin[ID]},${end[ID]}]%% ##}"
  911. s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}"
  912. services=($services $s)
  913. done
  914. fi
  915. # Names
  916. if [[ $type = (names|all) ]]; then
  917. for line in $lines; do
  918. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  919. s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}"
  920. services=($services $s)
  921. done
  922. fi
  923. _describe -t services-list "services" services "$@" && ret=0
  924. return ret
  925. }
  926. __docker_complete_services() {
  927. [[ $PREFIX = -* ]] && return 1
  928. __docker_services all "$@"
  929. }
  930. __docker_complete_services_ids() {
  931. [[ $PREFIX = -* ]] && return 1
  932. __docker_services ids "$@"
  933. }
  934. __docker_complete_services_names() {
  935. [[ $PREFIX = -* ]] && return 1
  936. __docker_services names "$@"
  937. }
  938. __docker_service_commands() {
  939. local -a _docker_service_subcommands
  940. _docker_service_subcommands=(
  941. "create:Create a new service"
  942. "inspect:Display detailed information on one or more services"
  943. "ls:List services"
  944. "rm:Remove one or more services"
  945. "scale:Scale one or multiple services"
  946. "ps:List the tasks of a service"
  947. "update:Update a service"
  948. )
  949. _describe -t docker-service-commands "docker service command" _docker_service_subcommands
  950. }
  951. __docker_service_subcommand() {
  952. local -a _command_args opts_help opts_create_update
  953. local expl help="--help"
  954. integer ret=1
  955. opts_help=("(: -)--help[Print usage]")
  956. opts_create_update=(
  957. "($help)*--constraint=[Placement constraints]:constraint: "
  958. "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)"
  959. "($help)*"{-e=,--env=}"[Set environment variables]:env: "
  960. "($help)*--group-add=[Add additional user groups to the container]:group:_groups"
  961. "($help)*--label=[Service labels]:label: "
  962. "($help)--limit-cpu=[Limit CPUs]:value: "
  963. "($help)--limit-memory=[Limit Memory]:value: "
  964. "($help)--log-driver=[Logging driver for service]:logging driver:__docker_log_drivers"
  965. "($help)*--log-opt=[Logging driver options]:log driver options:__docker_log_options"
  966. "($help)*--mount=[Attach a mount to the service]:mount: "
  967. "($help)--name=[Service name]:name: "
  968. "($help)*--network=[Network attachments]:network: "
  969. "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: "
  970. "($help)--replicas=[Number of tasks]:replicas: "
  971. "($help)--reserve-cpu=[Reserve CPUs]:value: "
  972. "($help)--reserve-memory=[Reserve Memory]:value: "
  973. "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)"
  974. "($help)--restart-delay=[Delay between restart attempts]:delay: "
  975. "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: "
  976. "($help)--restart-window=[Window used to evaluate the restart policy]:window: "
  977. "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: "
  978. "($help)--update-delay=[Delay between updates]:delay: "
  979. "($help)--update-failure-action=[Action on update failure]:mode:(pause continue)"
  980. "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: "
  981. "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: "
  982. "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: "
  983. "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
  984. "($help)--with-registry-auth[Send registry authentication details to swarm agents]"
  985. "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
  986. )
  987. case "$words[1]" in
  988. (create)
  989. _arguments $(__docker_arguments) \
  990. $opts_help \
  991. $opts_create_update \
  992. "($help)*--container-label=[Container labels]:label: " \
  993. "($help)--mode=[Service Mode]:mode:(global replicated)" \
  994. "($help -): :__docker_images" \
  995. "($help -):command: _command_names -e" \
  996. "($help -)*::arguments: _normal" && ret=0
  997. ;;
  998. (inspect)
  999. _arguments $(__docker_arguments) \
  1000. $opts_help \
  1001. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1002. "($help)--pretty[Print the information in a human friendly format]" \
  1003. "($help -)*:service:__docker_complete_services" && ret=0
  1004. ;;
  1005. (ls|list)
  1006. _arguments $(__docker_arguments) \
  1007. $opts_help \
  1008. "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:->filter-options" \
  1009. "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0
  1010. case $state in
  1011. (filter-options)
  1012. __docker_service_complete_ls_filters && ret=0
  1013. ;;
  1014. esac
  1015. ;;
  1016. (rm|remove)
  1017. _arguments $(__docker_arguments) \
  1018. $opts_help \
  1019. "($help -)*:service:__docker_complete_services" && ret=0
  1020. ;;
  1021. (scale)
  1022. _arguments $(__docker_arguments) \
  1023. $opts_help \
  1024. "($help -)*:service:->values" && ret=0
  1025. case $state in
  1026. (values)
  1027. if compset -P '*='; then
  1028. _message 'replicas' && ret=0
  1029. else
  1030. __docker_complete_services -qS "="
  1031. fi
  1032. ;;
  1033. esac
  1034. ;;
  1035. (ps)
  1036. _arguments $(__docker_arguments) \
  1037. $opts_help \
  1038. "($help -a --all)"{-a,--all}"[Display all tasks]" \
  1039. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  1040. "($help)--no-resolve[Do not map IDs to Names]" \
  1041. "($help)--no-trunc[Do not truncate output]" \
  1042. "($help -)1:service:__docker_complete_services" && ret=0
  1043. case $state in
  1044. (filter-options)
  1045. __docker_service_complete_ps_filters && ret=0
  1046. ;;
  1047. esac
  1048. ;;
  1049. (update)
  1050. _arguments $(__docker_arguments) \
  1051. $opts_help \
  1052. $opts_create_update \
  1053. "($help)--arg=[Service command args]:arguments: _normal" \
  1054. "($help)*--container-label-add=[Add or update container labels]:label: " \
  1055. "($help)*--container-label-rm=[Remove a container label by its key]:label: " \
  1056. "($help)--force[Force update]" \
  1057. "($help)*--group-rm=[Remove previously added user groups from the container]:group:_groups" \
  1058. "($help)--image=[Service image tag]:image:__docker_repositories" \
  1059. "($help)--rollback[Rollback to previous specification]" \
  1060. "($help -)1:service:__docker_complete_services" && ret=0
  1061. ;;
  1062. (help)
  1063. _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0
  1064. ;;
  1065. esac
  1066. return ret
  1067. }
  1068. # EO service
  1069. # BO swarm
  1070. __docker_swarm_commands() {
  1071. local -a _docker_swarm_subcommands
  1072. _docker_swarm_subcommands=(
  1073. "init:Initialize a swarm"
  1074. "join:Join a swarm as a node and/or manager"
  1075. "join-token:Manage join tokens"
  1076. "leave:Leave a swarm"
  1077. "update:Update the swarm"
  1078. )
  1079. _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands
  1080. }
  1081. __docker_swarm_subcommand() {
  1082. local -a _command_args opts_help
  1083. local expl help="--help"
  1084. integer ret=1
  1085. opts_help=("(: -)--help[Print usage]")
  1086. case "$words[1]" in
  1087. (init)
  1088. _arguments $(__docker_arguments) \
  1089. $opts_help \
  1090. "($help)--advertise-addr[Advertised address]:ip\:port: " \
  1091. "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \
  1092. "($help)--force-new-cluster[Force create a new cluster from current state]" \
  1093. "($help)--listen-addr=[Listen address]:ip\:port: " && ret=0
  1094. ;;
  1095. (join)
  1096. _arguments $(__docker_arguments) \
  1097. $opts_help \
  1098. "($help)--advertise-addr[Advertised address]:ip\:port: " \
  1099. "($help)--listen-addr=[Listen address]:ip\:port: " \
  1100. "($help)--token=[Token for entry into the swarm]:secret: " \
  1101. "($help -):host\:port: " && ret=0
  1102. ;;
  1103. (join-token)
  1104. _arguments $(__docker_arguments) \
  1105. $opts_help \
  1106. "($help -q --quiet)"{-q,--quiet}"[Only display token]" \
  1107. "($help)--rotate[Rotate join token]" \
  1108. "($help -):role:(manager worker)" && ret=0
  1109. ;;
  1110. (leave)
  1111. _arguments $(__docker_arguments) \
  1112. $opts_help && ret=0
  1113. ;;
  1114. (update)
  1115. _arguments $(__docker_arguments) \
  1116. $opts_help \
  1117. "($help)--cert-expiry=[Validity period for node certificates]:duration: " \
  1118. "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \
  1119. "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0
  1120. ;;
  1121. (help)
  1122. _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
  1123. ;;
  1124. esac
  1125. return ret
  1126. }
  1127. # EO swarm
  1128. # BO volume
  1129. __docker_volume_complete_ls_filters() {
  1130. [[ $PREFIX = -* ]] && return 1
  1131. integer ret=1
  1132. if compset -P '*='; then
  1133. case "${${words[-1]%=*}#*=}" in
  1134. (dangling)
  1135. dangling_opts=('true' 'false')
  1136. _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0
  1137. ;;
  1138. (driver)
  1139. __docker_complete_info_plugins Volume && ret=0
  1140. ;;
  1141. (name)
  1142. __docker_volumes && ret=0
  1143. ;;
  1144. *)
  1145. _message 'value' && ret=0
  1146. ;;
  1147. esac
  1148. else
  1149. opts=('dangling' 'driver' 'label' 'name')
  1150. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  1151. fi
  1152. return ret
  1153. }
  1154. __docker_volumes() {
  1155. [[ $PREFIX = -* ]] && return 1
  1156. integer ret=1
  1157. declare -a lines volumes
  1158. lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}})
  1159. # Parse header line to find columns
  1160. local i=1 j=1 k header=${lines[1]}
  1161. declare -A begin end
  1162. while (( j < ${#header} - 1 )); do
  1163. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  1164. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  1165. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  1166. begin[${header[$i,$((j-1))]}]=$i
  1167. end[${header[$i,$((j-1))]}]=$k
  1168. done
  1169. end[${header[$i,$((j-1))]}]=-1
  1170. lines=(${lines[2,-1]})
  1171. # Names
  1172. local line s
  1173. for line in $lines; do
  1174. s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}"
  1175. s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
  1176. volumes=($volumes $s)
  1177. done
  1178. _describe -t volumes-list "volumes" volumes && ret=0
  1179. return ret
  1180. }
  1181. __docker_volume_commands() {
  1182. local -a _docker_volume_subcommands
  1183. _docker_volume_subcommands=(
  1184. "create:Create a volume"
  1185. "inspect:Display detailed information on one or more volumes"
  1186. "ls:List volumes"
  1187. "rm:Remove one or more volumes"
  1188. )
  1189. _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands
  1190. }
  1191. __docker_volume_subcommand() {
  1192. local -a _command_args opts_help
  1193. local expl help="--help"
  1194. integer ret=1
  1195. opts_help=("(: -)--help[Print usage]")
  1196. case "$words[1]" in
  1197. (create)
  1198. _arguments $(__docker_arguments) -A '-*' \
  1199. $opts_help \
  1200. "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \
  1201. "($help)*--label=[Set metadata for a volume]:label=value: " \
  1202. "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \
  1203. "($help -)1:Volume name: " && ret=0
  1204. ;;
  1205. (inspect)
  1206. _arguments $(__docker_arguments) \
  1207. $opts_help \
  1208. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1209. "($help -)1:volume:__docker_volumes" && ret=0
  1210. ;;
  1211. (ls)
  1212. _arguments $(__docker_arguments) \
  1213. $opts_help \
  1214. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  1215. "($help)--format=[Pretty-print volumes using a Go template]:template: " \
  1216. "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0
  1217. case $state in
  1218. (filter-options)
  1219. __docker_volume_complete_ls_filters && ret=0
  1220. ;;
  1221. esac
  1222. ;;
  1223. (rm)
  1224. _arguments $(__docker_arguments) \
  1225. $opts_help \
  1226. "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \
  1227. "($help -):volume:__docker_volumes" && ret=0
  1228. ;;
  1229. (help)
  1230. _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0
  1231. ;;
  1232. esac
  1233. return ret
  1234. }
  1235. # EO volume
  1236. __docker_caching_policy() {
  1237. oldp=( "$1"(Nmh+1) ) # 1 hour
  1238. (( $#oldp ))
  1239. }
  1240. __docker_commands() {
  1241. local cache_policy
  1242. zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  1243. if [[ -z "$cache_policy" ]]; then
  1244. zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
  1245. fi
  1246. if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \
  1247. && ! _retrieve_cache docker_subcommands;
  1248. then
  1249. local -a lines
  1250. lines=(${(f)"$(_call_program commands docker 2>&1)"})
  1251. _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:})
  1252. _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command')
  1253. (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands
  1254. fi
  1255. _describe -t docker-commands "docker command" _docker_subcommands
  1256. }
  1257. __docker_subcommand() {
  1258. local -a _command_args opts_help opts_build_create_run opts_build_create_run_update opts_create_run opts_create_run_update
  1259. local expl help="--help"
  1260. integer ret=1
  1261. opts_help=("(: -)--help[Print usage]")
  1262. opts_build_create_run=(
  1263. "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: "
  1264. "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)"
  1265. "($help)--disable-content-trust[Skip image verification]"
  1266. "($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: "
  1267. "($help)*--ulimit=[ulimit options]:ulimit: "
  1268. "($help)--userns=[Container user namespace]:user namespace:(host)"
  1269. )
  1270. opts_build_create_run_update=(
  1271. "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)"
  1272. "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: "
  1273. "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: "
  1274. "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: "
  1275. "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: "
  1276. "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: "
  1277. "($help)--memory-swap=[Total memory limit with swap]:Memory limit: "
  1278. )
  1279. opts_create_run=(
  1280. "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
  1281. "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: "
  1282. "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: "
  1283. "($help)*--cap-add=[Add Linux capabilities]:capability: "
  1284. "($help)*--cap-drop=[Drop Linux capabilities]:capability: "
  1285. "($help)--cidfile=[Write the container ID to the file]:CID file:_files"
  1286. "($help)*--device=[Add a host device to the container]:device:_files"
  1287. "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: "
  1288. "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: "
  1289. "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: "
  1290. "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: "
  1291. "($help)*--dns=[Custom DNS servers]:DNS server: "
  1292. "($help)*--dns-opt=[Custom DNS options]:DNS option: "
  1293. "($help)*--dns-search=[Custom DNS search domains]:DNS domains: "
  1294. "($help)*"{-e=,--env=}"[Environment variables]:environment variable: "
  1295. "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: "
  1296. "($help)*--env-file=[Read environment variables from a file]:environment file:_files"
  1297. "($help)*--expose=[Expose a port from the container without publishing it]: "
  1298. "($help)*--group-add=[Add additional groups to run as]:group:_groups"
  1299. "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts"
  1300. "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]"
  1301. "($help)--ip=[Container IPv4 address]:IPv4: "
  1302. "($help)--ip6=[Container IPv6 address]:IPv6: "
  1303. "($help)--ipc=[IPC namespace to use]:IPC namespace: "
  1304. "($help)*--link=[Add link to another container]:link:->link"
  1305. "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: "
  1306. "($help)*"{-l=,--label=}"[Container metadata]:label: "
  1307. "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers"
  1308. "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options"
  1309. "($help)--mac-address=[Container MAC address]:MAC address: "
  1310. "($help)--name=[Container name]:name: "
  1311. "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)"
  1312. "($help)*--network-alias=[Add network-scoped alias for the container]:alias: "
  1313. "($help)--oom-kill-disable[Disable OOM Killer]"
  1314. "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]"
  1315. "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]"
  1316. "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
  1317. "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports"
  1318. "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid"
  1319. "($help)--privileged[Give extended privileges to this container]"
  1320. "($help)--read-only[Mount the container's root filesystem as read only]"
  1321. "($help)*--security-opt=[Security options]:security option: "
  1322. "($help)*--sysctl=-[sysctl options]:sysctl: "
  1323. "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]"
  1324. "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
  1325. "($help)--tmpfs[mount tmpfs]"
  1326. "($help)*-v[Bind mount a volume]:volume: "
  1327. "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)"
  1328. "($help)*--volumes-from=[Mount volumes from the specified container]:volume: "
  1329. "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
  1330. )
  1331. opts_create_run_update=(
  1332. "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)"
  1333. "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: "
  1334. "($help)--memory-reservation=[Memory soft limit]:Memory limit: "
  1335. "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)"
  1336. )
  1337. opts_attach_exec_run_start=(
  1338. "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys"
  1339. )
  1340. case "$words[1]" in
  1341. (attach)
  1342. _arguments $(__docker_arguments) \
  1343. $opts_help \
  1344. $opts_attach_exec_run_start \
  1345. "($help)--no-stdin[Do not attach stdin]" \
  1346. "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
  1347. "($help -):containers:__docker_runningcontainers" && ret=0
  1348. ;;
  1349. (build)
  1350. _arguments $(__docker_arguments) \
  1351. $opts_help \
  1352. $opts_build_create_run \
  1353. $opts_build_create_run_update \
  1354. "($help)*--build-arg[Build-time variables]:<varname>=<value>: " \
  1355. "($help)--compress[Compress the build context using gzip]" \
  1356. "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \
  1357. "($help)--force-rm[Always remove intermediate containers]" \
  1358. "($help)*--label=[Set metadata for an image]:label=value: " \
  1359. "($help)--no-cache[Do not use cache when building the image]" \
  1360. "($help)--pull[Attempt to pull a newer version of the image]" \
  1361. "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \
  1362. "($help)--rm[Remove intermediate containers after a successful build]" \
  1363. "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \
  1364. "($help -):path or URL:_directories" && ret=0
  1365. ;;
  1366. (commit)
  1367. _arguments $(__docker_arguments) \
  1368. $opts_help \
  1369. "($help -a --author)"{-a=,--author=}"[Author]:author: " \
  1370. "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
  1371. "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \
  1372. "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \
  1373. "($help -):container:__docker_containers" \
  1374. "($help -): :__docker_repositories_with_tags" && ret=0
  1375. ;;
  1376. (cp)
  1377. _arguments $(__docker_arguments) \
  1378. $opts_help \
  1379. "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \
  1380. "($help -)1:container:->container" \
  1381. "($help -)2:hostpath:_files" && ret=0
  1382. case $state in
  1383. (container)
  1384. if compset -P "*:"; then
  1385. _files && ret=0
  1386. else
  1387. __docker_containers -qS ":" && ret=0
  1388. fi
  1389. ;;
  1390. esac
  1391. ;;
  1392. (create)
  1393. _arguments $(__docker_arguments) \
  1394. $opts_help \
  1395. $opts_build_create_run \
  1396. $opts_build_create_run_update \
  1397. $opts_create_run \
  1398. $opts_create_run_update \
  1399. "($help -): :__docker_images" \
  1400. "($help -):command: _command_names -e" \
  1401. "($help -)*::arguments: _normal" && ret=0
  1402. case $state in
  1403. (link)
  1404. if compset -P "*:"; then
  1405. _wanted alias expl "Alias" compadd -E "" && ret=0
  1406. else
  1407. __docker_runningcontainers -qS ":" && ret=0
  1408. fi
  1409. ;;
  1410. esac
  1411. ;;
  1412. (daemon)
  1413. _arguments $(__docker_arguments) \
  1414. $opts_help \
  1415. "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \
  1416. "($help)--api-cors-header=[CORS headers in the remote API]:CORS headers: " \
  1417. "($help)*--authorization-plugin=[Authorization plugins to load]" \
  1418. "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \
  1419. "($help)--bip=[Network bridge IP]:IP address: " \
  1420. "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \
  1421. "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \
  1422. "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \
  1423. "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
  1424. "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \
  1425. "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \
  1426. "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \
  1427. "($help)--cluster-advertise=[Address or interface name to advertise]:Instance to advertise (host\:port): " \
  1428. "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \
  1429. "($help)*--dns=[DNS server to use]:DNS: " \
  1430. "($help)*--dns-search=[DNS search domains to use]:DNS search: " \
  1431. "($help)*--dns-opt=[DNS options to use]:DNS option: " \
  1432. "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \
  1433. "($help)--disable-legacy-registry[Disable contacting legacy registries]" \
  1434. "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \
  1435. "($help)--exec-root=[Root directory for execution state files]:path:_directories" \
  1436. "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \
  1437. "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \
  1438. "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \
  1439. "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \
  1440. "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
  1441. "($help)--icc[Enable inter-container communication]" \
  1442. "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \
  1443. "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \
  1444. "($help)--ip=[Default IP when binding container ports]" \
  1445. "($help)--ip-forward[Enable net.ipv4.ip_forward]" \
  1446. "($help)--ip-masq[Enable IP masquerading]" \
  1447. "($help)--iptables[Enable addition of iptables rules]" \
  1448. "($help)--ipv6[Enable IPv6 networking]" \
  1449. "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
  1450. "($help)*--label=[Key=value labels]:label: " \
  1451. "($help)--live-restore[Enable live restore of docker when containers are still running]" \
  1452. "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers" \
  1453. "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_log_options" \
  1454. "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \
  1455. "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \
  1456. "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \
  1457. "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \
  1458. "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \
  1459. "($help)--raw-logs[Full timestamps without ANSI coloring]" \
  1460. "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \
  1461. "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \
  1462. "($help)--selinux-enabled[Enable selinux support]" \
  1463. "($help)*--storage-opt=[Storage driver options]:storage driver options: " \
  1464. "($help)--tls[Use TLS]" \
  1465. "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \
  1466. "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \
  1467. "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \
  1468. "($help)--tlsverify[Use TLS and verify the remote]" \
  1469. "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \
  1470. "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0
  1471. case $state in
  1472. (cluster-store)
  1473. if compset -P '*://'; then
  1474. _message 'host:port' && ret=0
  1475. else
  1476. store=('consul' 'etcd' 'zk')
  1477. _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0
  1478. fi
  1479. ;;
  1480. (cluster-store-options)
  1481. if compset -P '*='; then
  1482. _files && ret=0
  1483. else
  1484. opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path')
  1485. _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0
  1486. fi
  1487. ;;
  1488. (users-groups)
  1489. if compset -P '*:'; then
  1490. _groups && ret=0
  1491. else
  1492. _describe -t userns-default "default Docker user management" '(default)' && ret=0
  1493. _users && ret=0
  1494. fi
  1495. ;;
  1496. esac
  1497. ;;
  1498. (diff)
  1499. _arguments $(__docker_arguments) \
  1500. $opts_help \
  1501. "($help -)*:containers:__docker_containers" && ret=0
  1502. ;;
  1503. (events)
  1504. _arguments $(__docker_arguments) \
  1505. $opts_help \
  1506. "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \
  1507. "($help)--since=[Events created since this timestamp]:timestamp: " \
  1508. "($help)--until=[Events created until this timestamp]:timestamp: " \
  1509. "($help)--format=[Format the output using the given go template]:template: " && ret=0
  1510. ;;
  1511. (exec)
  1512. local state
  1513. _arguments $(__docker_arguments) \
  1514. $opts_help \
  1515. $opts_attach_exec_run_start \
  1516. "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1517. "($help -e --env)"{-e,--env}"[Set environment variables]" \
  1518. "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \
  1519. "($help)--privileged[Give extended Linux capabilities to the command]" \
  1520. "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
  1521. "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \
  1522. "($help -):containers:__docker_runningcontainers" \
  1523. "($help -)*::command:->anycommand" && ret=0
  1524. case $state in
  1525. (anycommand)
  1526. shift 1 words
  1527. (( CURRENT-- ))
  1528. _normal && ret=0
  1529. ;;
  1530. esac
  1531. ;;
  1532. (export)
  1533. _arguments $(__docker_arguments) \
  1534. $opts_help \
  1535. "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \
  1536. "($help -)*:containers:__docker_containers" && ret=0
  1537. ;;
  1538. (history)
  1539. _arguments $(__docker_arguments) \
  1540. $opts_help \
  1541. "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \
  1542. "($help)--no-trunc[Do not truncate output]" \
  1543. "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1544. "($help -)*: :__docker_images" && ret=0
  1545. ;;
  1546. (images)
  1547. _arguments $(__docker_arguments) \
  1548. $opts_help \
  1549. "($help -a --all)"{-a,--all}"[Show all images]" \
  1550. "($help)--digests[Show digests]" \
  1551. "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1552. "($help)--format=[Pretty-print images using a Go template]:template: " \
  1553. "($help)--no-trunc[Do not truncate output]" \
  1554. "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1555. "($help -): :__docker_repositories" && ret=0
  1556. case $state in
  1557. (filter-options)
  1558. __docker_complete_images_filters && ret=0
  1559. ;;
  1560. esac
  1561. ;;
  1562. (import)
  1563. _arguments $(__docker_arguments) \
  1564. $opts_help \
  1565. "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
  1566. "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \
  1567. "($help -):URL:(- http:// file://)" \
  1568. "($help -): :__docker_repositories_with_tags" && ret=0
  1569. ;;
  1570. (info|version)
  1571. _arguments $(__docker_arguments) \
  1572. $opts_help \
  1573. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0
  1574. ;;
  1575. (inspect)
  1576. local state
  1577. _arguments $(__docker_arguments) \
  1578. $opts_help \
  1579. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1580. "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \
  1581. "($help)--type=[Return JSON for specified type]:type:(image container)" \
  1582. "($help -)*: :->values" && ret=0
  1583. case $state in
  1584. (values)
  1585. if [[ ${words[(r)--type=container]} == --type=container ]]; then
  1586. __docker_containers && ret=0
  1587. elif [[ ${words[(r)--type=image]} == --type=image ]]; then
  1588. __docker_images && ret=0
  1589. else
  1590. __docker_images && __docker_containers && ret=0
  1591. fi
  1592. ;;
  1593. esac
  1594. ;;
  1595. (kill)
  1596. _arguments $(__docker_arguments) \
  1597. $opts_help \
  1598. "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \
  1599. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1600. ;;
  1601. (load)
  1602. _arguments $(__docker_arguments) \
  1603. $opts_help \
  1604. "($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))(-.)\"" \
  1605. "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0
  1606. ;;
  1607. (login)
  1608. _arguments $(__docker_arguments) \
  1609. $opts_help \
  1610. "($help -p --password)"{-p=,--password=}"[Password]:password: " \
  1611. "($help -u --user)"{-u=,--user=}"[Username]:username: " \
  1612. "($help -)1:server: " && ret=0
  1613. ;;
  1614. (logout)
  1615. _arguments $(__docker_arguments) \
  1616. $opts_help \
  1617. "($help -)1:server: " && ret=0
  1618. ;;
  1619. (logs)
  1620. _arguments $(__docker_arguments) \
  1621. $opts_help \
  1622. "($help)--details[Show extra details provided to logs]" \
  1623. "($help -f --follow)"{-f,--follow}"[Follow log output]" \
  1624. "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \
  1625. "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \
  1626. "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \
  1627. "($help -)*:containers:__docker_containers" && ret=0
  1628. ;;
  1629. (network)
  1630. local curcontext="$curcontext" state
  1631. _arguments $(__docker_arguments) \
  1632. $opts_help \
  1633. "($help -): :->command" \
  1634. "($help -)*:: :->option-or-argument" && ret=0
  1635. case $state in
  1636. (command)
  1637. __docker_network_commands && ret=0
  1638. ;;
  1639. (option-or-argument)
  1640. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1641. __docker_network_subcommand && ret=0
  1642. ;;
  1643. esac
  1644. ;;
  1645. (node)
  1646. local curcontext="$curcontext" state
  1647. _arguments $(__docker_arguments) \
  1648. $opts_help \
  1649. "($help -): :->command" \
  1650. "($help -)*:: :->option-or-argument" && ret=0
  1651. case $state in
  1652. (command)
  1653. __docker_node_commands && ret=0
  1654. ;;
  1655. (option-or-argument)
  1656. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1657. __docker_node_subcommand && ret=0
  1658. ;;
  1659. esac
  1660. ;;
  1661. (pause|unpause)
  1662. _arguments $(__docker_arguments) \
  1663. $opts_help \
  1664. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1665. ;;
  1666. (plugin)
  1667. local curcontext="$curcontext" state
  1668. _arguments $(__docker_arguments) \
  1669. $opts_help \
  1670. "($help -): :->command" \
  1671. "($help -)*:: :->option-or-argument" && ret=0
  1672. case $state in
  1673. (command)
  1674. __docker_plugin_commands && ret=0
  1675. ;;
  1676. (option-or-argument)
  1677. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1678. __docker_plugin_subcommand && ret=0
  1679. ;;
  1680. esac
  1681. ;;
  1682. (port)
  1683. _arguments $(__docker_arguments) \
  1684. $opts_help \
  1685. "($help -)1:containers:__docker_runningcontainers" \
  1686. "($help -)2:port:_ports" && ret=0
  1687. ;;
  1688. (ps)
  1689. _arguments $(__docker_arguments) \
  1690. $opts_help \
  1691. "($help -a --all)"{-a,--all}"[Show all containers]" \
  1692. "($help)--before=[Show only container created before...]:containers:__docker_containers" \
  1693. "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \
  1694. "($help)--format=[Pretty-print containers using a Go template]:template: " \
  1695. "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \
  1696. "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \
  1697. "($help)--no-trunc[Do not truncate output]" \
  1698. "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1699. "($help -s --size)"{-s,--size}"[Display total file sizes]" \
  1700. "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0
  1701. ;;
  1702. (pull)
  1703. _arguments $(__docker_arguments) \
  1704. $opts_help \
  1705. "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \
  1706. "($help)--disable-content-trust[Skip image verification]" \
  1707. "($help -):name:__docker_search" && ret=0
  1708. ;;
  1709. (push)
  1710. _arguments $(__docker_arguments) \
  1711. $opts_help \
  1712. "($help)--disable-content-trust[Skip image signing]" \
  1713. "($help -): :__docker_images" && ret=0
  1714. ;;
  1715. (rename)
  1716. _arguments $(__docker_arguments) \
  1717. $opts_help \
  1718. "($help -):old name:__docker_containers" \
  1719. "($help -):new name: " && ret=0
  1720. ;;
  1721. (stop)
  1722. _arguments $(__docker_arguments) \
  1723. $opts_help \
  1724. "($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)" \
  1725. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1726. ;;
  1727. (restart)
  1728. _arguments $(__docker_arguments) \
  1729. $opts_help \
  1730. "($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)" \
  1731. "($help -)*:containers:__docker_containers_ids" && ret=0
  1732. ;;
  1733. (rm)
  1734. _arguments $(__docker_arguments) \
  1735. $opts_help \
  1736. "($help -f --force)"{-f,--force}"[Force removal]" \
  1737. "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \
  1738. "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \
  1739. "($help -)*:containers:->values" && ret=0
  1740. case $state in
  1741. (values)
  1742. if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then
  1743. __docker_containers && ret=0
  1744. else
  1745. __docker_stoppedcontainers && ret=0
  1746. fi
  1747. ;;
  1748. esac
  1749. ;;
  1750. (rmi)
  1751. _arguments $(__docker_arguments) \
  1752. $opts_help \
  1753. "($help -f --force)"{-f,--force}"[Force removal]" \
  1754. "($help)--no-prune[Do not delete untagged parents]" \
  1755. "($help -)*: :__docker_images" && ret=0
  1756. ;;
  1757. (run)
  1758. _arguments $(__docker_arguments) \
  1759. $opts_help \
  1760. $opts_build_create_run \
  1761. $opts_build_create_run_update \
  1762. $opts_create_run \
  1763. $opts_create_run_update \
  1764. $opts_attach_exec_run_start \
  1765. "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1766. "($help)--health-cmd=[Command to run to check health]:command: " \
  1767. "($help)--health-interval=[Time between running the check]:time: " \
  1768. "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \
  1769. "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \
  1770. "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \
  1771. "($help)--rm[Remove intermediate containers when it exits]" \
  1772. "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \
  1773. "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
  1774. "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \
  1775. "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \
  1776. "($help -): :__docker_images" \
  1777. "($help -):command: _command_names -e" \
  1778. "($help -)*::arguments: _normal" && ret=0
  1779. case $state in
  1780. (link)
  1781. if compset -P "*:"; then
  1782. _wanted alias expl "Alias" compadd -E "" && ret=0
  1783. else
  1784. __docker_runningcontainers -qS ":" && ret=0
  1785. fi
  1786. ;;
  1787. (storage-opt)
  1788. if compset -P "*="; then
  1789. _message "value" && ret=0
  1790. else
  1791. opts=('size')
  1792. _describe -t filter-opts "storage options" opts -qS "=" && ret=0
  1793. fi
  1794. ;;
  1795. esac
  1796. ;;
  1797. (save)
  1798. _arguments $(__docker_arguments) \
  1799. $opts_help \
  1800. "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \
  1801. "($help -)*: :__docker_images" && ret=0
  1802. ;;
  1803. (search)
  1804. _arguments $(__docker_arguments) \
  1805. $opts_help \
  1806. "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1807. "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \
  1808. "($help)--no-trunc[Do not truncate output]" \
  1809. "($help -):term: " && ret=0
  1810. case $state in
  1811. (filter-options)
  1812. __docker_complete_search_filters && ret=0
  1813. ;;
  1814. esac
  1815. ;;
  1816. (service)
  1817. local curcontext="$curcontext" state
  1818. _arguments $(__docker_arguments) \
  1819. $opts_help \
  1820. "($help -): :->command" \
  1821. "($help -)*:: :->option-or-argument" && ret=0
  1822. case $state in
  1823. (command)
  1824. __docker_service_commands && ret=0
  1825. ;;
  1826. (option-or-argument)
  1827. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1828. __docker_service_subcommand && ret=0
  1829. ;;
  1830. esac
  1831. ;;
  1832. (start)
  1833. _arguments $(__docker_arguments) \
  1834. $opts_help \
  1835. $opts_attach_exec_run_start \
  1836. "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \
  1837. "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \
  1838. "($help -)*:containers:__docker_stoppedcontainers" && ret=0
  1839. ;;
  1840. (stats)
  1841. _arguments $(__docker_arguments) \
  1842. $opts_help \
  1843. "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \
  1844. "($help)--format=[Pretty-print images using a Go template]:template: " \
  1845. "($help)--no-stream[Disable streaming stats and only pull the first result]" \
  1846. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1847. ;;
  1848. (swarm)
  1849. local curcontext="$curcontext" state
  1850. _arguments $(__docker_arguments) \
  1851. $opts_help \
  1852. "($help -): :->command" \
  1853. "($help -)*:: :->option-or-argument" && ret=0
  1854. case $state in
  1855. (command)
  1856. __docker_swarm_commands && ret=0
  1857. ;;
  1858. (option-or-argument)
  1859. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1860. __docker_swarm_subcommand && ret=0
  1861. ;;
  1862. esac
  1863. ;;
  1864. (tag)
  1865. _arguments $(__docker_arguments) \
  1866. $opts_help \
  1867. "($help -):source:__docker_images"\
  1868. "($help -):destination:__docker_repositories_with_tags" && ret=0
  1869. ;;
  1870. (top)
  1871. _arguments $(__docker_arguments) \
  1872. $opts_help \
  1873. "($help -)1:containers:__docker_runningcontainers" \
  1874. "($help -)*:: :->ps-arguments" && ret=0
  1875. case $state in
  1876. (ps-arguments)
  1877. _ps && ret=0
  1878. ;;
  1879. esac
  1880. ;;
  1881. (update)
  1882. _arguments $(__docker_arguments) \
  1883. $opts_help \
  1884. $opts_create_run_update \
  1885. $opts_build_create_run_update \
  1886. "($help -)*: :->values" && ret=0
  1887. case $state in
  1888. (values)
  1889. if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then
  1890. __docker_stoppedcontainers && ret=0
  1891. else
  1892. __docker_containers && ret=0
  1893. fi
  1894. ;;
  1895. esac
  1896. ;;
  1897. (volume)
  1898. local curcontext="$curcontext" state
  1899. _arguments $(__docker_arguments) \
  1900. $opts_help \
  1901. "($help -): :->command" \
  1902. "($help -)*:: :->option-or-argument" && ret=0
  1903. case $state in
  1904. (command)
  1905. __docker_volume_commands && ret=0
  1906. ;;
  1907. (option-or-argument)
  1908. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1909. __docker_volume_subcommand && ret=0
  1910. ;;
  1911. esac
  1912. ;;
  1913. (wait)
  1914. _arguments $(__docker_arguments) \
  1915. $opts_help \
  1916. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1917. ;;
  1918. (help)
  1919. _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0
  1920. ;;
  1921. esac
  1922. return ret
  1923. }
  1924. _docker() {
  1925. # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
  1926. # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
  1927. if [[ $service != docker ]]; then
  1928. _call_function - _$service
  1929. return
  1930. fi
  1931. local curcontext="$curcontext" state line help="-h --help"
  1932. integer ret=1
  1933. typeset -A opt_args
  1934. _arguments $(__docker_arguments) -C \
  1935. "(: -)"{-h,--help}"[Print usage]" \
  1936. "($help)--config[Location of client config files]:path:_directories" \
  1937. "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
  1938. "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
  1939. "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
  1940. "($help)--tls[Use TLS]" \
  1941. "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
  1942. "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
  1943. "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
  1944. "($help)--tlsverify[Use TLS and verify the remote]" \
  1945. "($help)--userland-proxy[Use userland proxy for loopback traffic]" \
  1946. "($help -v --version)"{-v,--version}"[Print version information and quit]" \
  1947. "($help -): :->command" \
  1948. "($help -)*:: :->option-or-argument" && ret=0
  1949. local host=${opt_args[-H]}${opt_args[--host]}
  1950. local config=${opt_args[--config]}
  1951. local docker_options="${host:+--host $host} ${config:+--config $config}"
  1952. case $state in
  1953. (command)
  1954. __docker_commands && ret=0
  1955. ;;
  1956. (option-or-argument)
  1957. curcontext=${curcontext%:*:*}:docker-$words[1]:
  1958. __docker_subcommand && ret=0
  1959. ;;
  1960. esac
  1961. return ret
  1962. }
  1963. _dockerd() {
  1964. integer ret=1
  1965. words[1]='daemon'
  1966. __docker_subcommand && ret=0
  1967. return ret
  1968. }
  1969. _docker "$@"
  1970. # Local Variables:
  1971. # mode: Shell-Script
  1972. # sh-indentation: 4
  1973. # indent-tabs-mode: nil
  1974. # sh-basic-offset: 4
  1975. # End:
  1976. # vim: ft=zsh sw=4 ts=4 et