_docker 123 KB

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