_docker 123 KB

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