_docker 124 KB

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