_docker 123 KB

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