_docker 122 KB

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