_docker 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  1. #compdef docker dockerd
  2. #
  3. # zsh completion for docker (http://docker.com)
  4. #
  5. # version: 0.3.0
  6. # github: https://github.com/felixr/docker-zsh-completion
  7. #
  8. # contributors:
  9. # - Felix Riedel
  10. # - Steve Durrheimer
  11. # - Vincent Bernat
  12. #
  13. # license:
  14. #
  15. # Copyright (c) 2013, Felix Riedel
  16. # All rights reserved.
  17. #
  18. # Redistribution and use in source and binary forms, with or without
  19. # modification, are permitted provided that the following conditions are met:
  20. # * Redistributions of source code must retain the above copyright
  21. # notice, this list of conditions and the following disclaimer.
  22. # * Redistributions in binary form must reproduce the above copyright
  23. # notice, this list of conditions and the following disclaimer in the
  24. # documentation and/or other materials provided with the distribution.
  25. # * Neither the name of the <organization> nor the
  26. # names of its contributors may be used to endorse or promote products
  27. # derived from this software without specific prior written permission.
  28. #
  29. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  30. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32. # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  33. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  34. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  36. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. #
  40. # Short-option stacking can be enabled with:
  41. # zstyle ':completion:*:*:docker:*' option-stacking yes
  42. # zstyle ':completion:*:*:docker-*:*' option-stacking yes
  43. __docker_arguments() {
  44. if zstyle -t ":completion:${curcontext}:" option-stacking; then
  45. print -- -s
  46. fi
  47. }
  48. __docker_get_containers() {
  49. [[ $PREFIX = -* ]] && return 1
  50. integer ret=1
  51. local kind type line s
  52. declare -a running stopped lines args names
  53. kind=$1; shift
  54. type=$1; shift
  55. [[ $kind = (stopped|all) ]] && args=($args -a)
  56. lines=(${(f)"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"})
  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* ]]; 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* ]]; 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_stoppedcontainers() {
  108. [[ $PREFIX = -* ]] && return 1
  109. __docker_get_containers stopped all "$@"
  110. }
  111. __docker_runningcontainers() {
  112. [[ $PREFIX = -* ]] && return 1
  113. __docker_get_containers running all "$@"
  114. }
  115. __docker_containers() {
  116. [[ $PREFIX = -* ]] && return 1
  117. __docker_get_containers all all "$@"
  118. }
  119. __docker_containers_ids() {
  120. [[ $PREFIX = -* ]] && return 1
  121. __docker_get_containers all ids "$@"
  122. }
  123. __docker_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_images() {
  138. [[ $PREFIX = -* ]] && return 1
  139. integer ret=1
  140. declare -a images
  141. images=(${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}})
  142. _describe -t docker-images "images" images && ret=0
  143. __docker_repositories_with_tags && ret=0
  144. return ret
  145. }
  146. __docker_repositories() {
  147. [[ $PREFIX = -* ]] && return 1
  148. declare -a repos
  149. repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]})
  150. repos=(${repos#<none>})
  151. _describe -t docker-repos "repositories" repos
  152. }
  153. __docker_repositories_with_tags() {
  154. [[ $PREFIX = -* ]] && return 1
  155. integer ret=1
  156. declare -a repos onlyrepos matched
  157. declare m
  158. repos=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/:::}%% *})
  159. repos=(${${repos%:::<none>}#<none>})
  160. # Check if we have a prefix-match for the current prefix.
  161. onlyrepos=(${repos%::*})
  162. for m in $onlyrepos; do
  163. [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && {
  164. # Yes, complete with tags
  165. repos=(${${repos/:::/:}/:/\\:})
  166. _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0
  167. return ret
  168. }
  169. done
  170. # No, only complete repositories
  171. onlyrepos=(${${repos%:::*}/:/\\:})
  172. _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0
  173. return ret
  174. }
  175. __docker_search() {
  176. [[ $PREFIX = -* ]] && return 1
  177. local cache_policy
  178. zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  179. if [[ -z "$cache_policy" ]]; then
  180. zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
  181. fi
  182. local searchterm cachename
  183. searchterm="${words[$CURRENT]%/}"
  184. cachename=_docker-search-$searchterm
  185. local expl
  186. local -a result
  187. if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \
  188. && ! _retrieve_cache ${cachename#_}; then
  189. _message "Searching for ${searchterm}..."
  190. result=(${${${(f)"$(_call_program commands docker $docker_options search $searchterm)"}%% *}[2,-1]})
  191. _store_cache ${cachename#_} result
  192. fi
  193. _wanted dockersearch expl 'available images' compadd -a result
  194. }
  195. __docker_get_log_options() {
  196. [[ $PREFIX = -* ]] && return 1
  197. integer ret=1
  198. local log_driver=${opt_args[--log-driver]:-"all"}
  199. local -a awslogs_options fluentd_options gelf_options journald_options json_file_options syslog_options splunk_options
  200. awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream")
  201. fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag")
  202. gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels")
  203. gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag")
  204. journald_options=("env" "labels" "tag")
  205. json_file_options=("env" "labels" "max-file" "max-size")
  206. syslog_options=("env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag")
  207. splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "tag")
  208. [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0
  209. [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0
  210. [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0
  211. [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0
  212. [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0
  213. [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0
  214. [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0
  215. [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0
  216. return ret
  217. }
  218. __docker_log_drivers() {
  219. [[ $PREFIX = -* ]] && return 1
  220. integer ret=1
  221. drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog)
  222. _describe -t log-drivers "log drivers" drivers && ret=0
  223. return ret
  224. }
  225. __docker_log_options() {
  226. [[ $PREFIX = -* ]] && return 1
  227. integer ret=1
  228. if compset -P '*='; then
  229. case "${${words[-1]%=*}#*=}" in
  230. (syslog-format)
  231. syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro')
  232. _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0
  233. ;;
  234. *)
  235. _message 'value' && ret=0
  236. ;;
  237. esac
  238. else
  239. __docker_get_log_options -qS "=" && ret=0
  240. fi
  241. return ret
  242. }
  243. __docker_complete_detach_keys() {
  244. [[ $PREFIX = -* ]] && return 1
  245. integer ret=1
  246. compset -P "*,"
  247. keys=(${:-{a-z}})
  248. ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}})
  249. _describe -t detach_keys "[a-z]" keys -qS "," && ret=0
  250. _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0
  251. }
  252. __docker_complete_pid() {
  253. [[ $PREFIX = -* ]] && return 1
  254. integer ret=1
  255. local -a opts vopts
  256. opts=('host')
  257. vopts=('container')
  258. if compset -P '*:'; then
  259. case "${${words[-1]%:*}#*=}" in
  260. (container)
  261. __docker_runningcontainers && ret=0
  262. ;;
  263. *)
  264. _message 'value' && ret=0
  265. ;;
  266. esac
  267. else
  268. _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0
  269. _describe -t pid-opts "PID Options" opts && ret=0
  270. fi
  271. return ret
  272. }
  273. __docker_complete_runtimes() {
  274. [[ $PREFIX = -* ]] && return 1
  275. integer ret=1
  276. emulate -L zsh
  277. setopt extendedglob
  278. local -a runtimes_opts
  279. runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}})
  280. _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0
  281. }
  282. __docker_complete_ps_filters() {
  283. [[ $PREFIX = -* ]] && return 1
  284. integer ret=1
  285. if compset -P '*='; then
  286. case "${${words[-1]%=*}#*=}" in
  287. (ancestor)
  288. __docker_images && ret=0
  289. ;;
  290. (before|since)
  291. __docker_containers && ret=0
  292. ;;
  293. (id)
  294. __docker_containers_ids && ret=0
  295. ;;
  296. (name)
  297. __docker_containers_names && ret=0
  298. ;;
  299. (network)
  300. __docker_networks && ret=0
  301. ;;
  302. (status)
  303. status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running')
  304. _describe -t status-filter-opts "Status Filter Options" status_opts && ret=0
  305. ;;
  306. (volume)
  307. __docker_volumes && ret=0
  308. ;;
  309. *)
  310. _message 'value' && ret=0
  311. ;;
  312. esac
  313. else
  314. opts=('ancestor' 'before' 'exited' 'id' 'label' 'name' 'network' 'since' 'status' 'volume')
  315. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  316. fi
  317. return ret
  318. }
  319. __docker_complete_search_filters() {
  320. [[ $PREFIX = -* ]] && return 1
  321. integer ret=1
  322. declare -a boolean_opts opts
  323. boolean_opts=('true' 'false')
  324. opts=('is-automated' 'is-official' 'stars')
  325. if compset -P '*='; then
  326. case "${${words[-1]%=*}#*=}" in
  327. (is-automated|is-official)
  328. _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
  329. ;;
  330. *)
  331. _message 'value' && ret=0
  332. ;;
  333. esac
  334. else
  335. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  336. fi
  337. return ret
  338. }
  339. __docker_complete_images_filters() {
  340. [[ $PREFIX = -* ]] && return 1
  341. integer ret=1
  342. declare -a boolean_opts opts
  343. boolean_opts=('true' 'false')
  344. opts=('before' 'dangling' 'label' 'since')
  345. if compset -P '*='; then
  346. case "${${words[-1]%=*}#*=}" in
  347. (before|since)
  348. __docker_images && ret=0
  349. ;;
  350. (dangling)
  351. _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
  352. ;;
  353. *)
  354. _message 'value' && ret=0
  355. ;;
  356. esac
  357. else
  358. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  359. fi
  360. return ret
  361. }
  362. __docker_complete_events_filter() {
  363. [[ $PREFIX = -* ]] && return 1
  364. integer ret=1
  365. declare -a opts
  366. opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume')
  367. if compset -P '*='; then
  368. case "${${words[-1]%=*}#*=}" in
  369. (container)
  370. __docker_containers && ret=0
  371. ;;
  372. (daemon)
  373. emulate -L zsh
  374. setopt extendedglob
  375. local -a daemon_opts
  376. daemon_opts=(
  377. ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}}
  378. ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:}
  379. )
  380. _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0
  381. ;;
  382. (event)
  383. local -a event_opts
  384. event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach'
  385. 'exec_start' 'export' 'import' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start'
  386. 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update')
  387. _describe -t event-filter-opts "event filter options" event_opts && ret=0
  388. ;;
  389. (image)
  390. __docker_images && ret=0
  391. ;;
  392. (network)
  393. __docker_networks && ret=0
  394. ;;
  395. (type)
  396. local -a type_opts
  397. type_opts=('container' 'daemon' 'image' 'network' 'volume')
  398. _describe -t type-filter-opts "type filter options" type_opts && ret=0
  399. ;;
  400. (volume)
  401. __docker_volumes && ret=0
  402. ;;
  403. *)
  404. _message 'value' && ret=0
  405. ;;
  406. esac
  407. else
  408. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  409. fi
  410. return ret
  411. }
  412. __docker_network_complete_ls_filters() {
  413. [[ $PREFIX = -* ]] && return 1
  414. integer ret=1
  415. if compset -P '*='; then
  416. case "${${words[-1]%=*}#*=}" in
  417. (driver)
  418. __docker_complete_info_plugins Network && ret=0
  419. ;;
  420. (id)
  421. __docker_networks_ids && ret=0
  422. ;;
  423. (name)
  424. __docker_networks_names && ret=0
  425. ;;
  426. (type)
  427. type_opts=('builtin' 'custom')
  428. _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0
  429. ;;
  430. *)
  431. _message 'value' && ret=0
  432. ;;
  433. esac
  434. else
  435. opts=('driver' 'id' 'label' 'name' 'type')
  436. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  437. fi
  438. return ret
  439. }
  440. __docker_get_networks() {
  441. [[ $PREFIX = -* ]] && return 1
  442. integer ret=1
  443. local line s
  444. declare -a lines networks
  445. type=$1; shift
  446. lines=(${(f)"$(_call_program commands docker $docker_options network ls)"})
  447. # Parse header line to find columns
  448. local i=1 j=1 k header=${lines[1]}
  449. declare -A begin end
  450. while (( j < ${#header} - 1 )); do
  451. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  452. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  453. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  454. begin[${header[$i,$((j-1))]}]=$i
  455. end[${header[$i,$((j-1))]}]=$k
  456. done
  457. end[${header[$i,$((j-1))]}]=-1
  458. lines=(${lines[2,-1]})
  459. # Network ID
  460. if [[ $type = (ids|all) ]]; then
  461. for line in $lines; do
  462. s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}"
  463. s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
  464. networks=($networks $s)
  465. done
  466. fi
  467. # Names
  468. if [[ $type = (names|all) ]]; then
  469. for line in $lines; do
  470. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  471. s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
  472. networks=($networks $s)
  473. done
  474. fi
  475. _describe -t networks-list "networks" networks "$@" && ret=0
  476. return ret
  477. }
  478. __docker_networks() {
  479. [[ $PREFIX = -* ]] && return 1
  480. __docker_get_networks all "$@"
  481. }
  482. __docker_networks_ids() {
  483. [[ $PREFIX = -* ]] && return 1
  484. __docker_get_networks ids "$@"
  485. }
  486. __docker_networks_names() {
  487. [[ $PREFIX = -* ]] && return 1
  488. __docker_get_networks names "$@"
  489. }
  490. __docker_network_commands() {
  491. local -a _docker_network_subcommands
  492. _docker_network_subcommands=(
  493. "connect:Connect a container to a network"
  494. "create:Creates a new network with a name specified by the user"
  495. "disconnect:Disconnects a container from a network"
  496. "inspect:Displays detailed information on a network"
  497. "ls:Lists all the networks created by the user"
  498. "rm:Deletes one or more networks"
  499. )
  500. _describe -t docker-network-commands "docker network command" _docker_network_subcommands
  501. }
  502. __docker_network_subcommand() {
  503. local -a _command_args opts_help
  504. local expl help="--help"
  505. integer ret=1
  506. opts_help=("(: -)--help[Print usage]")
  507. case "$words[1]" in
  508. (connect)
  509. _arguments $(__docker_arguments) \
  510. $opts_help \
  511. "($help)*--alias=[Add network-scoped alias for the container]:alias: " \
  512. "($help)--ip=[Container IPv4 address]:IPv4: " \
  513. "($help)--ip6=[Container IPv6 address]:IPv6: " \
  514. "($help)*--link=[Add a link to another container]:link:->link" \
  515. "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \
  516. "($help -)1:network:__docker_networks" \
  517. "($help -)2:containers:__docker_containers" && ret=0
  518. case $state in
  519. (link)
  520. if compset -P "*:"; then
  521. _wanted alias expl "Alias" compadd -E "" && ret=0
  522. else
  523. __docker_runningcontainers -qS ":" && ret=0
  524. fi
  525. ;;
  526. esac
  527. ;;
  528. (create)
  529. _arguments $(__docker_arguments) -A '-*' \
  530. $opts_help \
  531. "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \
  532. "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \
  533. "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \
  534. "($help)--internal[Restricts external access to the network]" \
  535. "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \
  536. "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \
  537. "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \
  538. "($help)--ipv6[Enable IPv6 networking]" \
  539. "($help)*--label=[Set metadata on a network]:label=value: " \
  540. "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \
  541. "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \
  542. "($help -)1:Network Name: " && ret=0
  543. ;;
  544. (disconnect)
  545. _arguments $(__docker_arguments) \
  546. $opts_help \
  547. "($help -)1:network:__docker_networks" \
  548. "($help -)2:containers:__docker_containers" && ret=0
  549. ;;
  550. (inspect)
  551. _arguments $(__docker_arguments) \
  552. $opts_help \
  553. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  554. "($help -)*:network:__docker_networks" && ret=0
  555. ;;
  556. (ls)
  557. _arguments $(__docker_arguments) \
  558. $opts_help \
  559. "($help)--no-trunc[Do not truncate the output]" \
  560. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  561. "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0
  562. case $state in
  563. (filter-options)
  564. __docker_network_complete_ls_filters && ret=0
  565. ;;
  566. esac
  567. ;;
  568. (rm)
  569. _arguments $(__docker_arguments) \
  570. $opts_help \
  571. "($help -)*:network:__docker_networks" && ret=0
  572. ;;
  573. (help)
  574. _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
  575. ;;
  576. esac
  577. return ret
  578. }
  579. # BO node
  580. __docker_node_complete_ls_filters() {
  581. [[ $PREFIX = -* ]] && return 1
  582. integer ret=1
  583. if compset -P '*='; then
  584. case "${${words[-1]%=*}#*=}" in
  585. (id)
  586. __docker_complete_nodes_ids && ret=0
  587. ;;
  588. (membership)
  589. membership_opts=('accepted' 'pending' 'rejected')
  590. _describe -t membership-opts "membership options" membership_opts && ret=0
  591. ;;
  592. (name)
  593. __docker_complete_nodes_names && ret=0
  594. ;;
  595. (role)
  596. role_opts=('manager' 'worker')
  597. _describe -t role-opts "role options" role_opts && ret=0
  598. ;;
  599. *)
  600. _message 'value' && ret=0
  601. ;;
  602. esac
  603. else
  604. opts=('id' 'label' 'membership' 'name' 'role')
  605. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  606. fi
  607. return ret
  608. }
  609. __docker_node_complete_ps_filters() {
  610. [[ $PREFIX = -* ]] && return 1
  611. integer ret=1
  612. if compset -P '*='; then
  613. case "${${words[-1]%=*}#*=}" in
  614. (desired-state)
  615. state_opts=('accepted' 'running')
  616. _describe -t state-opts "desired state options" state_opts && ret=0
  617. ;;
  618. *)
  619. _message 'value' && ret=0
  620. ;;
  621. esac
  622. else
  623. opts=('desired-state' 'id' 'label' 'name')
  624. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  625. fi
  626. return ret
  627. }
  628. __docker_nodes() {
  629. [[ $PREFIX = -* ]] && return 1
  630. integer ret=1
  631. local line s
  632. declare -a lines nodes args
  633. type=$1; shift
  634. filter=$1; shift
  635. [[ $filter != "none" ]] && args=("-f $filter")
  636. lines=(${(f)"$(_call_program commands docker $docker_options node ls $args)"})
  637. # Parse header line to find columns
  638. local i=1 j=1 k header=${lines[1]}
  639. declare -A begin end
  640. while (( j < ${#header} - 1 )); do
  641. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  642. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  643. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  644. begin[${header[$i,$((j-1))]}]=$i
  645. end[${header[$i,$((j-1))]}]=$k
  646. done
  647. end[${header[$i,$((j-1))]}]=-1
  648. lines=(${lines[2,-1]})
  649. # Node ID
  650. if [[ $type = (ids|all) ]]; then
  651. for line in $lines; do
  652. s="${line[${begin[ID]},${end[ID]}]%% ##}"
  653. nodes=($nodes $s)
  654. done
  655. fi
  656. # Names
  657. if [[ $type = (names|all) ]]; then
  658. for line in $lines; do
  659. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  660. nodes=($nodes $s)
  661. done
  662. fi
  663. _describe -t nodes-list "nodes" nodes "$@" && ret=0
  664. return ret
  665. }
  666. __docker_complete_nodes() {
  667. [[ $PREFIX = -* ]] && return 1
  668. __docker_nodes all none "$@"
  669. }
  670. __docker_complete_nodes_ids() {
  671. [[ $PREFIX = -* ]] && return 1
  672. __docker_nodes ids none "$@"
  673. }
  674. __docker_complete_nodes_names() {
  675. [[ $PREFIX = -* ]] && return 1
  676. __docker_nodes names none "$@"
  677. }
  678. __docker_complete_pending_nodes() {
  679. [[ $PREFIX = -* ]] && return 1
  680. __docker_nodes all "membership=pending" "$@"
  681. }
  682. __docker_complete_manager_nodes() {
  683. [[ $PREFIX = -* ]] && return 1
  684. __docker_nodes all "role=manager" "$@"
  685. }
  686. __docker_complete_worker_nodes() {
  687. [[ $PREFIX = -* ]] && return 1
  688. __docker_nodes all "role=worker" "$@"
  689. }
  690. __docker_node_commands() {
  691. local -a _docker_node_subcommands
  692. _docker_node_subcommands=(
  693. "demote:Demote a node as manager in the swarm"
  694. "inspect:Display detailed information on one or more nodes"
  695. "ls:List nodes in the swarm"
  696. "promote:Promote a node as manager in the swarm"
  697. "rm:Remove one or more nodes from the swarm"
  698. "ps:List tasks running on a node"
  699. "update:Update a node"
  700. )
  701. _describe -t docker-node-commands "docker node command" _docker_node_subcommands
  702. }
  703. __docker_node_subcommand() {
  704. local -a _command_args opts_help
  705. local expl help="--help"
  706. integer ret=1
  707. opts_help=("(: -)--help[Print usage]")
  708. case "$words[1]" in
  709. (rm|remove)
  710. _arguments $(__docker_arguments) \
  711. $opts_help \
  712. "($help -)*:node:__docker_complete_pending_nodes" && ret=0
  713. ;;
  714. (demote)
  715. _arguments $(__docker_arguments) \
  716. $opts_help \
  717. "($help -)*:node:__docker_complete_manager_nodes" && ret=0
  718. ;;
  719. (inspect)
  720. _arguments $(__docker_arguments) \
  721. $opts_help \
  722. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  723. "($help)--pretty[Print the information in a human friendly format]" \
  724. "($help -)*:node:__docker_complete_nodes" && ret=0
  725. ;;
  726. (ls|list)
  727. _arguments $(__docker_arguments) \
  728. $opts_help \
  729. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  730. "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0
  731. case $state in
  732. (filter-options)
  733. __docker_node_complete_ls_filters && ret=0
  734. ;;
  735. esac
  736. ;;
  737. (promote)
  738. _arguments $(__docker_arguments) \
  739. $opts_help \
  740. "($help -)*:node:__docker_complete_worker_nodes" && ret=0
  741. ;;
  742. (ps)
  743. _arguments $(__docker_arguments) \
  744. $opts_help \
  745. "($help -a --all)"{-a,--all}"[Display all instances]" \
  746. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  747. "($help)--no-resolve[Do not map IDs to Names]" \
  748. "($help -)1:node:__docker_complete_nodes" && ret=0
  749. case $state in
  750. (filter-options)
  751. __docker_node_complete_ps_filters && ret=0
  752. ;;
  753. esac
  754. ;;
  755. (update)
  756. _arguments $(__docker_arguments) \
  757. $opts_help \
  758. "($help)--availability=[Availability of the node]:availability:(active pause drain)" \
  759. "($help)*--label-add=[Add or update a node label]:key=value: " \
  760. "($help)*--label-rm=[Remove a node label if exists]:label: " \
  761. "($help)--role=[Role of the node]:role:(manager worker)" \
  762. "($help -)1:node:__docker_complete_nodes" && ret=0
  763. ;;
  764. (help)
  765. _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0
  766. ;;
  767. esac
  768. return ret
  769. }
  770. # EO node
  771. # BO plugin
  772. __docker_complete_plugins() {
  773. [[ $PREFIX = -* ]] && return 1
  774. integer ret=1
  775. local line s
  776. declare -a lines plugins
  777. lines=(${(f)"$(_call_program commands docker $docker_options plugin ls)"})
  778. # Parse header line to find columns
  779. local i=1 j=1 k header=${lines[1]}
  780. declare -A begin end
  781. while (( j < ${#header} - 1 )); do
  782. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  783. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  784. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  785. begin[${header[$i,$((j-1))]}]=$i
  786. end[${header[$i,$((j-1))]}]=$k
  787. done
  788. end[${header[$i,$((j-1))]}]=-1
  789. lines=(${lines[2,-1]})
  790. # Name
  791. for line in $lines; do
  792. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  793. s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}"
  794. plugins=($plugins $s)
  795. done
  796. _describe -t plugins-list "plugins" plugins "$@" && ret=0
  797. return ret
  798. }
  799. __docker_plugin_commands() {
  800. local -a _docker_plugin_subcommands
  801. _docker_plugin_subcommands=(
  802. "disable:Disable a plugin"
  803. "enable:Enable a plugin"
  804. "inspect:Return low-level information about a plugin"
  805. "install:Install a plugin"
  806. "ls:List plugins"
  807. "push:Push a plugin"
  808. "rm:Remove a plugin"
  809. "set:Change settings for a plugin"
  810. )
  811. _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands
  812. }
  813. __docker_plugin_subcommand() {
  814. local -a _command_args opts_help
  815. local expl help="--help"
  816. integer ret=1
  817. opts_help=("(: -)--help[Print usage]")
  818. case "$words[1]" in
  819. (disable|enable|inspect|install|ls|push|rm)
  820. _arguments $(__docker_arguments) \
  821. $opts_help \
  822. "($help -)1:plugin:__docker_complete_plugins" && ret=0
  823. ;;
  824. (set)
  825. _arguments $(__docker_arguments) \
  826. $opts_help \
  827. "($help -)1:plugin:__docker_complete_plugins" \
  828. "($help-)*:key=value: " && ret=0
  829. ;;
  830. (help)
  831. _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0
  832. ;;
  833. esac
  834. return ret
  835. }
  836. # EO plugin
  837. # BO service
  838. __docker_service_complete_ls_filters() {
  839. [[ $PREFIX = -* ]] && return 1
  840. integer ret=1
  841. if compset -P '*='; then
  842. case "${${words[-1]%=*}#*=}" in
  843. (id)
  844. __docker_complete_services_ids && ret=0
  845. ;;
  846. (name)
  847. __docker_complete_services_names && ret=0
  848. ;;
  849. *)
  850. _message 'value' && ret=0
  851. ;;
  852. esac
  853. else
  854. opts=('id' 'label' 'name')
  855. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  856. fi
  857. return ret
  858. }
  859. __docker_service_complete_ps_filters() {
  860. [[ $PREFIX = -* ]] && return 1
  861. integer ret=1
  862. if compset -P '*='; then
  863. case "${${words[-1]%=*}#*=}" in
  864. (desired-state)
  865. state_opts=('accepted' 'running')
  866. _describe -t state-opts "desired state options" state_opts && ret=0
  867. ;;
  868. *)
  869. _message 'value' && ret=0
  870. ;;
  871. esac
  872. else
  873. opts=('desired-state' 'id' 'label' 'name')
  874. _describe -t filter-opts "filter options" opts -qS "=" && ret=0
  875. fi
  876. return ret
  877. }
  878. __docker_services() {
  879. [[ $PREFIX = -* ]] && return 1
  880. integer ret=1
  881. local line s
  882. declare -a lines services
  883. type=$1; shift
  884. lines=(${(f)"$(_call_program commands docker $docker_options service ls)"})
  885. # Parse header line to find columns
  886. local i=1 j=1 k header=${lines[1]}
  887. declare -A begin end
  888. while (( j < ${#header} - 1 )); do
  889. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  890. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  891. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  892. begin[${header[$i,$((j-1))]}]=$i
  893. end[${header[$i,$((j-1))]}]=$k
  894. done
  895. end[${header[$i,$((j-1))]}]=-1
  896. lines=(${lines[2,-1]})
  897. # Service ID
  898. if [[ $type = (ids|all) ]]; then
  899. for line in $lines; do
  900. s="${line[${begin[ID]},${end[ID]}]%% ##}"
  901. s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}"
  902. services=($services $s)
  903. done
  904. fi
  905. # Names
  906. if [[ $type = (names|all) ]]; then
  907. for line in $lines; do
  908. s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
  909. s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}"
  910. services=($services $s)
  911. done
  912. fi
  913. _describe -t services-list "services" services "$@" && ret=0
  914. return ret
  915. }
  916. __docker_complete_services() {
  917. [[ $PREFIX = -* ]] && return 1
  918. __docker_services all "$@"
  919. }
  920. __docker_complete_services_ids() {
  921. [[ $PREFIX = -* ]] && return 1
  922. __docker_services ids "$@"
  923. }
  924. __docker_complete_services_names() {
  925. [[ $PREFIX = -* ]] && return 1
  926. __docker_services names "$@"
  927. }
  928. __docker_service_commands() {
  929. local -a _docker_service_subcommands
  930. _docker_service_subcommands=(
  931. "create:Create a new service"
  932. "inspect:Display detailed information on one or more services"
  933. "ls:List services"
  934. "rm:Remove one or more services"
  935. "scale:Scale one or multiple services"
  936. "ps:List the tasks of a service"
  937. "update:Update a service"
  938. )
  939. _describe -t docker-service-commands "docker service command" _docker_service_subcommands
  940. }
  941. __docker_service_subcommand() {
  942. local -a _command_args opts_help opts_create_update
  943. local expl help="--help"
  944. integer ret=1
  945. opts_help=("(: -)--help[Print usage]")
  946. opts_create_update=(
  947. "($help)*--constraint=[Placement constraints]:constraint: "
  948. "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)"
  949. "($help)*"{-e=,--env=}"[Set environment variables]:env: "
  950. "($help)*--label=[Service labels]:label: "
  951. "($help)--limit-cpu=[Limit CPUs]:value: "
  952. "($help)--limit-memory=[Limit Memory]:value: "
  953. "($help)--log-driver=[Logging driver for service]:logging driver:__docker_log_drivers"
  954. "($help)*--log-opt=[Logging driver options]:log driver options:__docker_log_options"
  955. "($help)*--mount=[Attach a mount to the service]:mount: "
  956. "($help)--name=[Service name]:name: "
  957. "($help)*--network=[Network attachments]:network: "
  958. "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: "
  959. "($help)--replicas=[Number of tasks]:replicas: "
  960. "($help)--reserve-cpu=[Reserve CPUs]:value: "
  961. "($help)--reserve-memory=[Reserve Memory]:value: "
  962. "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)"
  963. "($help)--restart-delay=[Delay between restart attempts]:delay: "
  964. "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: "
  965. "($help)--restart-window=[Window used to evaluate the restart policy]:window: "
  966. "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: "
  967. "($help)--update-delay=[Delay between updates]:delay: "
  968. "($help)--update-failure-action=[Action on update failure]:mode:(pause continue)"
  969. "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: "
  970. "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
  971. "($help)--with-registry-auth[Send registry authentication details to swarm agents]"
  972. "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
  973. )
  974. case "$words[1]" in
  975. (create)
  976. _arguments $(__docker_arguments) \
  977. $opts_help \
  978. $opts_create_update \
  979. "($help)*--container-label=[Container labels]:label: " \
  980. "($help)--mode=[Service Mode]:mode:(global replicated)" \
  981. "($help -): :__docker_images" \
  982. "($help -):command: _command_names -e" \
  983. "($help -)*::arguments: _normal" && ret=0
  984. ;;
  985. (inspect)
  986. _arguments $(__docker_arguments) \
  987. $opts_help \
  988. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  989. "($help)--pretty[Print the information in a human friendly format]" \
  990. "($help -)*:service:__docker_complete_services" && ret=0
  991. ;;
  992. (ls|list)
  993. _arguments $(__docker_arguments) \
  994. $opts_help \
  995. "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:->filter-options" \
  996. "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0
  997. case $state in
  998. (filter-options)
  999. __docker_service_complete_ls_filters && ret=0
  1000. ;;
  1001. esac
  1002. ;;
  1003. (rm|remove)
  1004. _arguments $(__docker_arguments) \
  1005. $opts_help \
  1006. "($help -)*:service:__docker_complete_services" && ret=0
  1007. ;;
  1008. (scale)
  1009. _arguments $(__docker_arguments) \
  1010. $opts_help \
  1011. "($help -)*:service:->values" && ret=0
  1012. case $state in
  1013. (values)
  1014. if compset -P '*='; then
  1015. _message 'replicas' && ret=0
  1016. else
  1017. __docker_complete_services -qS "="
  1018. fi
  1019. ;;
  1020. esac
  1021. ;;
  1022. (ps)
  1023. _arguments $(__docker_arguments) \
  1024. $opts_help \
  1025. "($help -a --all)"{-a,--all}"[Display all tasks]" \
  1026. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  1027. "($help)--no-resolve[Do not map IDs to Names]" \
  1028. "($help -)1:service:__docker_complete_services" && ret=0
  1029. case $state in
  1030. (filter-options)
  1031. __docker_service_complete_ps_filters && ret=0
  1032. ;;
  1033. esac
  1034. ;;
  1035. (update)
  1036. _arguments $(__docker_arguments) \
  1037. $opts_help \
  1038. $opts_create_update \
  1039. "($help)--arg=[Service command args]:arguments: _normal" \
  1040. "($help)*--container-label-add=[Add or update container labels]:label: " \
  1041. "($help)*--container-label-rm=[Remove a container label by its key]:label: " \
  1042. "($help)--image=[Service image tag]:image:__docker_repositories" \
  1043. "($help -)1:service:__docker_complete_services" && ret=0
  1044. ;;
  1045. (help)
  1046. _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0
  1047. ;;
  1048. esac
  1049. return ret
  1050. }
  1051. # EO service
  1052. # BO swarm
  1053. __docker_swarm_commands() {
  1054. local -a _docker_swarm_subcommands
  1055. _docker_swarm_subcommands=(
  1056. "init:Initialize a swarm"
  1057. "join:Join a swarm as a node and/or manager"
  1058. "join-token:Manage join tokens"
  1059. "leave:Leave a swarm"
  1060. "update:Update the swarm"
  1061. )
  1062. _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands
  1063. }
  1064. __docker_swarm_subcommand() {
  1065. local -a _command_args opts_help
  1066. local expl help="--help"
  1067. integer ret=1
  1068. opts_help=("(: -)--help[Print usage]")
  1069. case "$words[1]" in
  1070. (init)
  1071. _arguments $(__docker_arguments) \
  1072. $opts_help \
  1073. "($help)--advertise-addr[Advertised address]:ip\:port: " \
  1074. "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \
  1075. "($help)--force-new-cluster[Force create a new cluster from current state]" \
  1076. "($help)--listen-addr=[Listen address]:ip\:port: " && ret=0
  1077. ;;
  1078. (join)
  1079. _arguments $(__docker_arguments) \
  1080. $opts_help \
  1081. "($help)--advertise-addr[Advertised address]:ip\:port: " \
  1082. "($help)--listen-addr=[Listen address]:ip\:port: " \
  1083. "($help)--token=[Token for entry into the swarm]:secret: " \
  1084. "($help -):host\:port: " && ret=0
  1085. ;;
  1086. (join-token)
  1087. _arguments $(__docker_arguments) \
  1088. $opts_help \
  1089. "($help -q --quiet)"{-q,--quiet}"[Only display token]" \
  1090. "($help)--rotate[Rotate join token]" \
  1091. "($help -):role:(manager worker)" && ret=0
  1092. ;;
  1093. (leave)
  1094. _arguments $(__docker_arguments) \
  1095. $opts_help && ret=0
  1096. ;;
  1097. (update)
  1098. _arguments $(__docker_arguments) \
  1099. $opts_help \
  1100. "($help)--cert-expiry=[Validity period for node certificates]:duration: " \
  1101. "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \
  1102. "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0
  1103. ;;
  1104. (help)
  1105. _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0
  1106. ;;
  1107. esac
  1108. return ret
  1109. }
  1110. # EO swarm
  1111. __docker_volume_complete_ls_filters() {
  1112. [[ $PREFIX = -* ]] && return 1
  1113. integer ret=1
  1114. if compset -P '*='; then
  1115. case "${${words[-1]%=*}#*=}" in
  1116. (dangling)
  1117. dangling_opts=('true' 'false')
  1118. _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0
  1119. ;;
  1120. (driver)
  1121. __docker_complete_info_plugins Volume && ret=0
  1122. ;;
  1123. (name)
  1124. __docker_volumes && ret=0
  1125. ;;
  1126. *)
  1127. _message 'value' && ret=0
  1128. ;;
  1129. esac
  1130. else
  1131. opts=('dangling' 'driver' 'name')
  1132. _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0
  1133. fi
  1134. return ret
  1135. }
  1136. __docker_volumes() {
  1137. [[ $PREFIX = -* ]] && return 1
  1138. integer ret=1
  1139. declare -a lines volumes
  1140. lines=(${(f)"$(_call_program commands docker $docker_options volume ls)"})
  1141. # Parse header line to find columns
  1142. local i=1 j=1 k header=${lines[1]}
  1143. declare -A begin end
  1144. while (( j < ${#header} - 1 )); do
  1145. i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
  1146. j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
  1147. k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
  1148. begin[${header[$i,$((j-1))]}]=$i
  1149. end[${header[$i,$((j-1))]}]=$k
  1150. done
  1151. end[${header[$i,$((j-1))]}]=-1
  1152. lines=(${lines[2,-1]})
  1153. # Names
  1154. local line s
  1155. for line in $lines; do
  1156. s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}"
  1157. s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}"
  1158. volumes=($volumes $s)
  1159. done
  1160. _describe -t volumes-list "volumes" volumes && ret=0
  1161. return ret
  1162. }
  1163. __docker_volume_commands() {
  1164. local -a _docker_volume_subcommands
  1165. _docker_volume_subcommands=(
  1166. "create:Create a volume"
  1167. "inspect:Display detailed information on one or more volumes"
  1168. "ls:List volumes"
  1169. "rm:Remove one or more volumes"
  1170. )
  1171. _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands
  1172. }
  1173. __docker_volume_subcommand() {
  1174. local -a _command_args opts_help
  1175. local expl help="--help"
  1176. integer ret=1
  1177. opts_help=("(: -)--help[Print usage]")
  1178. case "$words[1]" in
  1179. (create)
  1180. _arguments $(__docker_arguments) \
  1181. $opts_help \
  1182. "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \
  1183. "($help)*--label=[Set metadata for a volume]:label=value: " \
  1184. "($help)--name=[Volume name]" \
  1185. "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " && ret=0
  1186. ;;
  1187. (inspect)
  1188. _arguments $(__docker_arguments) \
  1189. $opts_help \
  1190. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1191. "($help -)1:volume:__docker_volumes" && ret=0
  1192. ;;
  1193. (ls)
  1194. _arguments $(__docker_arguments) \
  1195. $opts_help \
  1196. "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \
  1197. "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0
  1198. case $state in
  1199. (filter-options)
  1200. __docker_volume_complete_ls_filters && ret=0
  1201. ;;
  1202. esac
  1203. ;;
  1204. (rm)
  1205. _arguments $(__docker_arguments) \
  1206. $opts_help \
  1207. "($help -):volume:__docker_volumes" && ret=0
  1208. ;;
  1209. (help)
  1210. _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0
  1211. ;;
  1212. esac
  1213. return ret
  1214. }
  1215. __docker_caching_policy() {
  1216. oldp=( "$1"(Nmh+1) ) # 1 hour
  1217. (( $#oldp ))
  1218. }
  1219. __docker_commands() {
  1220. local cache_policy
  1221. zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  1222. if [[ -z "$cache_policy" ]]; then
  1223. zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy
  1224. fi
  1225. if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \
  1226. && ! _retrieve_cache docker_subcommands;
  1227. then
  1228. local -a lines
  1229. lines=(${(f)"$(_call_program commands docker 2>&1)"})
  1230. _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:})
  1231. _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command')
  1232. (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands
  1233. fi
  1234. _describe -t docker-commands "docker command" _docker_subcommands
  1235. }
  1236. __docker_subcommand() {
  1237. local -a _command_args opts_help opts_build_create_run opts_build_create_run_update opts_create_run opts_create_run_update
  1238. local expl help="--help"
  1239. integer ret=1
  1240. opts_help=("(: -)--help[Print usage]")
  1241. opts_build_create_run=(
  1242. "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: "
  1243. "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)"
  1244. "($help)--disable-content-trust[Skip image verification]"
  1245. "($help)*--shm-size=[Size of '/dev/shm' (format is '<number><unit>')]:shm size: "
  1246. "($help)*--ulimit=[ulimit options]:ulimit: "
  1247. "($help)--userns=[Container user namespace]:user namespace:(host)"
  1248. )
  1249. opts_build_create_run_update=(
  1250. "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)"
  1251. "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: "
  1252. "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: "
  1253. "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: "
  1254. "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: "
  1255. "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: "
  1256. "($help)--memory-swap=[Total memory limit with swap]:Memory limit: "
  1257. )
  1258. opts_create_run=(
  1259. "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
  1260. "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: "
  1261. "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: "
  1262. "($help)*--cap-add=[Add Linux capabilities]:capability: "
  1263. "($help)*--cap-drop=[Drop Linux capabilities]:capability: "
  1264. "($help)--cidfile=[Write the container ID to the file]:CID file:_files"
  1265. "($help)*--device=[Add a host device to the container]:device:_files"
  1266. "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: "
  1267. "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: "
  1268. "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: "
  1269. "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: "
  1270. "($help)*--dns=[Custom DNS servers]:DNS server: "
  1271. "($help)*--dns-opt=[Custom DNS options]:DNS option: "
  1272. "($help)*--dns-search=[Custom DNS search domains]:DNS domains: "
  1273. "($help)*"{-e=,--env=}"[Environment variables]:environment variable: "
  1274. "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: "
  1275. "($help)*--env-file=[Read environment variables from a file]:environment file:_files"
  1276. "($help)*--expose=[Expose a port from the container without publishing it]: "
  1277. "($help)*--group-add=[Add additional groups to run as]:group:_groups"
  1278. "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts"
  1279. "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]"
  1280. "($help)--ip=[Container IPv4 address]:IPv4: "
  1281. "($help)--ip6=[Container IPv6 address]:IPv6: "
  1282. "($help)--ipc=[IPC namespace to use]:IPC namespace: "
  1283. "($help)*--link=[Add link to another container]:link:->link"
  1284. "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: "
  1285. "($help)*"{-l=,--label=}"[Container metadata]:label: "
  1286. "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers"
  1287. "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options"
  1288. "($help)--mac-address=[Container MAC address]:MAC address: "
  1289. "($help)--name=[Container name]:name: "
  1290. "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)"
  1291. "($help)*--network-alias=[Add network-scoped alias for the container]:alias: "
  1292. "($help)--oom-kill-disable[Disable OOM Killer]"
  1293. "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]"
  1294. "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]"
  1295. "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]"
  1296. "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports"
  1297. "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid"
  1298. "($help)--privileged[Give extended privileges to this container]"
  1299. "($help)--read-only[Mount the container's root filesystem as read only]"
  1300. "($help)*--security-opt=[Security options]:security option: "
  1301. "($help)*--sysctl=-[sysctl options]:sysctl: "
  1302. "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]"
  1303. "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
  1304. "($help)--tmpfs[mount tmpfs]"
  1305. "($help)*-v[Bind mount a volume]:volume: "
  1306. "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)"
  1307. "($help)*--volumes-from=[Mount volumes from the specified container]:volume: "
  1308. "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
  1309. )
  1310. opts_create_run_update=(
  1311. "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)"
  1312. "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: "
  1313. "($help)--memory-reservation=[Memory soft limit]:Memory limit: "
  1314. "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)"
  1315. )
  1316. opts_attach_exec_run_start=(
  1317. "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys"
  1318. )
  1319. case "$words[1]" in
  1320. (attach)
  1321. _arguments $(__docker_arguments) \
  1322. $opts_help \
  1323. $opts_attach_exec_run_start \
  1324. "($help)--no-stdin[Do not attach stdin]" \
  1325. "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
  1326. "($help -):containers:__docker_runningcontainers" && ret=0
  1327. ;;
  1328. (build)
  1329. _arguments $(__docker_arguments) \
  1330. $opts_help \
  1331. $opts_build_create_run \
  1332. $opts_build_create_run_update \
  1333. "($help)*--build-arg[Build-time variables]:<varname>=<value>: " \
  1334. "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \
  1335. "($help)--force-rm[Always remove intermediate containers]" \
  1336. "($help)*--label=[Set metadata for an image]:label=value: " \
  1337. "($help)--no-cache[Do not use cache when building the image]" \
  1338. "($help)--pull[Attempt to pull a newer version of the image]" \
  1339. "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \
  1340. "($help)--rm[Remove intermediate containers after a successful build]" \
  1341. "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \
  1342. "($help -):path or URL:_directories" && ret=0
  1343. ;;
  1344. (commit)
  1345. _arguments $(__docker_arguments) \
  1346. $opts_help \
  1347. "($help -a --author)"{-a=,--author=}"[Author]:author: " \
  1348. "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
  1349. "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \
  1350. "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \
  1351. "($help -):container:__docker_containers" \
  1352. "($help -): :__docker_repositories_with_tags" && ret=0
  1353. ;;
  1354. (cp)
  1355. _arguments $(__docker_arguments) \
  1356. $opts_help \
  1357. "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \
  1358. "($help -)1:container:->container" \
  1359. "($help -)2:hostpath:_files" && ret=0
  1360. case $state in
  1361. (container)
  1362. if compset -P "*:"; then
  1363. _files && ret=0
  1364. else
  1365. __docker_containers -qS ":" && ret=0
  1366. fi
  1367. ;;
  1368. esac
  1369. ;;
  1370. (create)
  1371. _arguments $(__docker_arguments) \
  1372. $opts_help \
  1373. $opts_build_create_run \
  1374. $opts_build_create_run_update \
  1375. $opts_create_run \
  1376. $opts_create_run_update \
  1377. "($help -): :__docker_images" \
  1378. "($help -):command: _command_names -e" \
  1379. "($help -)*::arguments: _normal" && ret=0
  1380. case $state in
  1381. (link)
  1382. if compset -P "*:"; then
  1383. _wanted alias expl "Alias" compadd -E "" && ret=0
  1384. else
  1385. __docker_runningcontainers -qS ":" && ret=0
  1386. fi
  1387. ;;
  1388. esac
  1389. ;;
  1390. (daemon)
  1391. _arguments $(__docker_arguments) \
  1392. $opts_help \
  1393. "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \
  1394. "($help)--api-cors-header=[CORS headers in the remote API]:CORS headers: " \
  1395. "($help)*--authorization-plugin=[Authorization plugins to load]" \
  1396. "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \
  1397. "($help)--bip=[Network bridge IP]:IP address: " \
  1398. "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \
  1399. "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \
  1400. "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \
  1401. "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
  1402. "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \
  1403. "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \
  1404. "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \
  1405. "($help)--cluster-advertise=[Address or interface name to advertise]:Instance to advertise (host\:port): " \
  1406. "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \
  1407. "($help)*--dns=[DNS server to use]:DNS: " \
  1408. "($help)*--dns-search=[DNS search domains to use]:DNS search: " \
  1409. "($help)*--dns-opt=[DNS options to use]:DNS option: " \
  1410. "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \
  1411. "($help)--disable-legacy-registry[Disable contacting legacy registries]" \
  1412. "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \
  1413. "($help)--exec-root=[Root directory for execution state files]:path:_directories" \
  1414. "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \
  1415. "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \
  1416. "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \
  1417. "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \
  1418. "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
  1419. "($help)--icc[Enable inter-container communication]" \
  1420. "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \
  1421. "($help)--ip=[Default IP when binding container ports]" \
  1422. "($help)--ip-forward[Enable net.ipv4.ip_forward]" \
  1423. "($help)--ip-masq[Enable IP masquerading]" \
  1424. "($help)--iptables[Enable addition of iptables rules]" \
  1425. "($help)--ipv6[Enable IPv6 networking]" \
  1426. "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
  1427. "($help)*--label=[Key=value labels]:label: " \
  1428. "($help)--live-restore[Enable live restore of docker when containers are still running]" \
  1429. "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers" \
  1430. "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_log_options" \
  1431. "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \
  1432. "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \
  1433. "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \
  1434. "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \
  1435. "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \
  1436. "($help)--raw-logs[Full timestamps without ANSI coloring]" \
  1437. "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \
  1438. "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \
  1439. "($help)--selinux-enabled[Enable selinux support]" \
  1440. "($help)*--storage-opt=[Storage driver options]:storage driver options: " \
  1441. "($help)--tls[Use TLS]" \
  1442. "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \
  1443. "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \
  1444. "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \
  1445. "($help)--tlsverify[Use TLS and verify the remote]" \
  1446. "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \
  1447. "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0
  1448. case $state in
  1449. (cluster-store)
  1450. if compset -P '*://'; then
  1451. _message 'host:port' && ret=0
  1452. else
  1453. store=('consul' 'etcd' 'zk')
  1454. _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0
  1455. fi
  1456. ;;
  1457. (cluster-store-options)
  1458. if compset -P '*='; then
  1459. _files && ret=0
  1460. else
  1461. opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path')
  1462. _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0
  1463. fi
  1464. ;;
  1465. (users-groups)
  1466. if compset -P '*:'; then
  1467. _groups && ret=0
  1468. else
  1469. _describe -t userns-default "default Docker user management" '(default)' && ret=0
  1470. _users && ret=0
  1471. fi
  1472. ;;
  1473. esac
  1474. ;;
  1475. (diff)
  1476. _arguments $(__docker_arguments) \
  1477. $opts_help \
  1478. "($help -)*:containers:__docker_containers" && ret=0
  1479. ;;
  1480. (events)
  1481. _arguments $(__docker_arguments) \
  1482. $opts_help \
  1483. "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \
  1484. "($help)--since=[Events created since this timestamp]:timestamp: " \
  1485. "($help)--until=[Events created until this timestamp]:timestamp: " && ret=0
  1486. ;;
  1487. (exec)
  1488. local state
  1489. _arguments $(__docker_arguments) \
  1490. $opts_help \
  1491. $opts_attach_exec_run_start \
  1492. "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1493. "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \
  1494. "($help)--privileged[Give extended Linux capabilities to the command]" \
  1495. "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
  1496. "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \
  1497. "($help -):containers:__docker_runningcontainers" \
  1498. "($help -)*::command:->anycommand" && ret=0
  1499. case $state in
  1500. (anycommand)
  1501. shift 1 words
  1502. (( CURRENT-- ))
  1503. _normal && ret=0
  1504. ;;
  1505. esac
  1506. ;;
  1507. (export)
  1508. _arguments $(__docker_arguments) \
  1509. $opts_help \
  1510. "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \
  1511. "($help -)*:containers:__docker_containers" && ret=0
  1512. ;;
  1513. (history)
  1514. _arguments $(__docker_arguments) \
  1515. $opts_help \
  1516. "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \
  1517. "($help)--no-trunc[Do not truncate output]" \
  1518. "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1519. "($help -)*: :__docker_images" && ret=0
  1520. ;;
  1521. (images)
  1522. _arguments $(__docker_arguments) \
  1523. $opts_help \
  1524. "($help -a --all)"{-a,--all}"[Show all images]" \
  1525. "($help)--digests[Show digests]" \
  1526. "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1527. "($help)--format[Pretty-print containers using a Go template]:format: " \
  1528. "($help)--no-trunc[Do not truncate output]" \
  1529. "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1530. "($help -): :__docker_repositories" && ret=0
  1531. case $state in
  1532. (filter-options)
  1533. __docker_complete_images_filters && ret=0
  1534. ;;
  1535. esac
  1536. ;;
  1537. (import)
  1538. _arguments $(__docker_arguments) \
  1539. $opts_help \
  1540. "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \
  1541. "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \
  1542. "($help -):URL:(- http:// file://)" \
  1543. "($help -): :__docker_repositories_with_tags" && ret=0
  1544. ;;
  1545. (info|version)
  1546. _arguments $(__docker_arguments) \
  1547. $opts_help && ret=0
  1548. ;;
  1549. (inspect)
  1550. local state
  1551. _arguments $(__docker_arguments) \
  1552. $opts_help \
  1553. "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \
  1554. "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \
  1555. "($help)--type=[Return JSON for specified type]:type:(image container)" \
  1556. "($help -)*: :->values" && ret=0
  1557. case $state in
  1558. (values)
  1559. if [[ ${words[(r)--type=container]} == --type=container ]]; then
  1560. __docker_containers && ret=0
  1561. elif [[ ${words[(r)--type=image]} == --type=image ]]; then
  1562. __docker_images && ret=0
  1563. else
  1564. __docker_images && __docker_containers && ret=0
  1565. fi
  1566. ;;
  1567. esac
  1568. ;;
  1569. (kill)
  1570. _arguments $(__docker_arguments) \
  1571. $opts_help \
  1572. "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \
  1573. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1574. ;;
  1575. (load)
  1576. _arguments $(__docker_arguments) \
  1577. $opts_help \
  1578. "($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))(-.)\"" \
  1579. "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0
  1580. ;;
  1581. (login)
  1582. _arguments $(__docker_arguments) \
  1583. $opts_help \
  1584. "($help -p --password)"{-p=,--password=}"[Password]:password: " \
  1585. "($help -u --user)"{-u=,--user=}"[Username]:username: " \
  1586. "($help -)1:server: " && ret=0
  1587. ;;
  1588. (logout)
  1589. _arguments $(__docker_arguments) \
  1590. $opts_help \
  1591. "($help -)1:server: " && ret=0
  1592. ;;
  1593. (logs)
  1594. _arguments $(__docker_arguments) \
  1595. $opts_help \
  1596. "($help)--details[Show extra details provided to logs]" \
  1597. "($help -f --follow)"{-f,--follow}"[Follow log output]" \
  1598. "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \
  1599. "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \
  1600. "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \
  1601. "($help -)*:containers:__docker_containers" && ret=0
  1602. ;;
  1603. (network)
  1604. local curcontext="$curcontext" state
  1605. _arguments $(__docker_arguments) \
  1606. $opts_help \
  1607. "($help -): :->command" \
  1608. "($help -)*:: :->option-or-argument" && ret=0
  1609. case $state in
  1610. (command)
  1611. __docker_network_commands && ret=0
  1612. ;;
  1613. (option-or-argument)
  1614. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1615. __docker_network_subcommand && ret=0
  1616. ;;
  1617. esac
  1618. ;;
  1619. (node)
  1620. local curcontext="$curcontext" state
  1621. _arguments $(__docker_arguments) \
  1622. $opts_help \
  1623. "($help -): :->command" \
  1624. "($help -)*:: :->option-or-argument" && ret=0
  1625. case $state in
  1626. (command)
  1627. __docker_node_commands && ret=0
  1628. ;;
  1629. (option-or-argument)
  1630. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1631. __docker_node_subcommand && ret=0
  1632. ;;
  1633. esac
  1634. ;;
  1635. (pause|unpause)
  1636. _arguments $(__docker_arguments) \
  1637. $opts_help \
  1638. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1639. ;;
  1640. (plugin)
  1641. local curcontext="$curcontext" state
  1642. _arguments $(__docker_arguments) \
  1643. $opts_help \
  1644. "($help -): :->command" \
  1645. "($help -)*:: :->option-or-argument" && ret=0
  1646. case $state in
  1647. (command)
  1648. __docker_plugin_commands && ret=0
  1649. ;;
  1650. (option-or-argument)
  1651. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1652. __docker_plugin_subcommand && ret=0
  1653. ;;
  1654. esac
  1655. ;;
  1656. (port)
  1657. _arguments $(__docker_arguments) \
  1658. $opts_help \
  1659. "($help -)1:containers:__docker_runningcontainers" \
  1660. "($help -)2:port:_ports" && ret=0
  1661. ;;
  1662. (ps)
  1663. _arguments $(__docker_arguments) \
  1664. $opts_help \
  1665. "($help -a --all)"{-a,--all}"[Show all containers]" \
  1666. "($help)--before=[Show only container created before...]:containers:__docker_containers" \
  1667. "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \
  1668. "($help)--format[Pretty-print containers using a Go template]:format: " \
  1669. "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \
  1670. "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \
  1671. "($help)--no-trunc[Do not truncate output]" \
  1672. "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \
  1673. "($help -s --size)"{-s,--size}"[Display total file sizes]" \
  1674. "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0
  1675. ;;
  1676. (pull)
  1677. _arguments $(__docker_arguments) \
  1678. $opts_help \
  1679. "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \
  1680. "($help)--disable-content-trust[Skip image verification]" \
  1681. "($help -):name:__docker_search" && ret=0
  1682. ;;
  1683. (push)
  1684. _arguments $(__docker_arguments) \
  1685. $opts_help \
  1686. "($help)--disable-content-trust[Skip image signing]" \
  1687. "($help -): :__docker_images" && ret=0
  1688. ;;
  1689. (rename)
  1690. _arguments $(__docker_arguments) \
  1691. $opts_help \
  1692. "($help -):old name:__docker_containers" \
  1693. "($help -):new name: " && ret=0
  1694. ;;
  1695. (restart|stop)
  1696. _arguments $(__docker_arguments) \
  1697. $opts_help \
  1698. "($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)" \
  1699. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1700. ;;
  1701. (rm)
  1702. _arguments $(__docker_arguments) \
  1703. $opts_help \
  1704. "($help -f --force)"{-f,--force}"[Force removal]" \
  1705. "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \
  1706. "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \
  1707. "($help -)*:containers:->values" && ret=0
  1708. case $state in
  1709. (values)
  1710. if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then
  1711. __docker_containers && ret=0
  1712. else
  1713. __docker_stoppedcontainers && ret=0
  1714. fi
  1715. ;;
  1716. esac
  1717. ;;
  1718. (rmi)
  1719. _arguments $(__docker_arguments) \
  1720. $opts_help \
  1721. "($help -f --force)"{-f,--force}"[Force removal]" \
  1722. "($help)--no-prune[Do not delete untagged parents]" \
  1723. "($help -)*: :__docker_images" && ret=0
  1724. ;;
  1725. (run)
  1726. _arguments $(__docker_arguments) \
  1727. $opts_help \
  1728. $opts_build_create_run \
  1729. $opts_build_create_run_update \
  1730. $opts_create_run \
  1731. $opts_create_run_update \
  1732. $opts_attach_exec_run_start \
  1733. "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \
  1734. "($help)--health-cmd=[Command to run to check health]:command: " \
  1735. "($help)--health-interval=[Time between running the check]:time: " \
  1736. "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \
  1737. "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \
  1738. "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \
  1739. "($help)--rm[Remove intermediate containers when it exits]" \
  1740. "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \
  1741. "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \
  1742. "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \
  1743. "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \
  1744. "($help -): :__docker_images" \
  1745. "($help -):command: _command_names -e" \
  1746. "($help -)*::arguments: _normal" && ret=0
  1747. case $state in
  1748. (link)
  1749. if compset -P "*:"; then
  1750. _wanted alias expl "Alias" compadd -E "" && ret=0
  1751. else
  1752. __docker_runningcontainers -qS ":" && ret=0
  1753. fi
  1754. ;;
  1755. (storage-opt)
  1756. if compset -P "*="; then
  1757. _message "value" && ret=0
  1758. else
  1759. opts=('size')
  1760. _describe -t filter-opts "storage options" opts -qS "=" && ret=0
  1761. fi
  1762. ;;
  1763. esac
  1764. ;;
  1765. (save)
  1766. _arguments $(__docker_arguments) \
  1767. $opts_help \
  1768. "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \
  1769. "($help -)*: :__docker_images" && ret=0
  1770. ;;
  1771. (search)
  1772. _arguments $(__docker_arguments) \
  1773. $opts_help \
  1774. "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \
  1775. "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \
  1776. "($help)--no-trunc[Do not truncate output]" \
  1777. "($help -):term: " && ret=0
  1778. case $state in
  1779. (filter-options)
  1780. __docker_complete_search_filters && ret=0
  1781. ;;
  1782. esac
  1783. ;;
  1784. (service)
  1785. local curcontext="$curcontext" state
  1786. _arguments $(__docker_arguments) \
  1787. $opts_help \
  1788. "($help -): :->command" \
  1789. "($help -)*:: :->option-or-argument" && ret=0
  1790. case $state in
  1791. (command)
  1792. __docker_service_commands && ret=0
  1793. ;;
  1794. (option-or-argument)
  1795. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1796. __docker_service_subcommand && ret=0
  1797. ;;
  1798. esac
  1799. ;;
  1800. (start)
  1801. _arguments $(__docker_arguments) \
  1802. $opts_help \
  1803. $opts_attach_exec_run_start \
  1804. "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \
  1805. "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \
  1806. "($help -)*:containers:__docker_stoppedcontainers" && ret=0
  1807. ;;
  1808. (stats)
  1809. _arguments $(__docker_arguments) \
  1810. $opts_help \
  1811. "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \
  1812. "($help)--no-stream[Disable streaming stats and only pull the first result]" \
  1813. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1814. ;;
  1815. (swarm)
  1816. local curcontext="$curcontext" state
  1817. _arguments $(__docker_arguments) \
  1818. $opts_help \
  1819. "($help -): :->command" \
  1820. "($help -)*:: :->option-or-argument" && ret=0
  1821. case $state in
  1822. (command)
  1823. __docker_swarm_commands && ret=0
  1824. ;;
  1825. (option-or-argument)
  1826. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1827. __docker_swarm_subcommand && ret=0
  1828. ;;
  1829. esac
  1830. ;;
  1831. (tag)
  1832. _arguments $(__docker_arguments) \
  1833. $opts_help \
  1834. "($help -):source:__docker_images"\
  1835. "($help -):destination:__docker_repositories_with_tags" && ret=0
  1836. ;;
  1837. (top)
  1838. _arguments $(__docker_arguments) \
  1839. $opts_help \
  1840. "($help -)1:containers:__docker_runningcontainers" \
  1841. "($help -)*:: :->ps-arguments" && ret=0
  1842. case $state in
  1843. (ps-arguments)
  1844. _ps && ret=0
  1845. ;;
  1846. esac
  1847. ;;
  1848. (update)
  1849. _arguments $(__docker_arguments) \
  1850. $opts_help \
  1851. $opts_create_run_update \
  1852. $opts_build_create_run_update \
  1853. "($help -)*: :->values" && ret=0
  1854. case $state in
  1855. (values)
  1856. if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then
  1857. __docker_stoppedcontainers && ret=0
  1858. else
  1859. __docker_containers && ret=0
  1860. fi
  1861. ;;
  1862. esac
  1863. ;;
  1864. (volume)
  1865. local curcontext="$curcontext" state
  1866. _arguments $(__docker_arguments) \
  1867. $opts_help \
  1868. "($help -): :->command" \
  1869. "($help -)*:: :->option-or-argument" && ret=0
  1870. case $state in
  1871. (command)
  1872. __docker_volume_commands && ret=0
  1873. ;;
  1874. (option-or-argument)
  1875. curcontext=${curcontext%:*:*}:docker-${words[-1]}:
  1876. __docker_volume_subcommand && ret=0
  1877. ;;
  1878. esac
  1879. ;;
  1880. (wait)
  1881. _arguments $(__docker_arguments) \
  1882. $opts_help \
  1883. "($help -)*:containers:__docker_runningcontainers" && ret=0
  1884. ;;
  1885. (help)
  1886. _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0
  1887. ;;
  1888. esac
  1889. return ret
  1890. }
  1891. _docker() {
  1892. # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
  1893. # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
  1894. if [[ $service != docker ]]; then
  1895. _call_function - _$service
  1896. return
  1897. fi
  1898. local curcontext="$curcontext" state line help="-h --help"
  1899. integer ret=1
  1900. typeset -A opt_args
  1901. _arguments $(__docker_arguments) -C \
  1902. "(: -)"{-h,--help}"[Print usage]" \
  1903. "($help)--config[Location of client config files]:path:_directories" \
  1904. "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \
  1905. "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \
  1906. "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \
  1907. "($help)--tls[Use TLS]" \
  1908. "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \
  1909. "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \
  1910. "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \
  1911. "($help)--tlsverify[Use TLS and verify the remote]" \
  1912. "($help)--userland-proxy[Use userland proxy for loopback traffic]" \
  1913. "($help -v --version)"{-v,--version}"[Print version information and quit]" \
  1914. "($help -): :->command" \
  1915. "($help -)*:: :->option-or-argument" && ret=0
  1916. local host=${opt_args[-H]}${opt_args[--host]}
  1917. local config=${opt_args[--config]}
  1918. local docker_options="${host:+--host $host} ${config:+--config $config}"
  1919. case $state in
  1920. (command)
  1921. __docker_commands && ret=0
  1922. ;;
  1923. (option-or-argument)
  1924. curcontext=${curcontext%:*:*}:docker-$words[1]:
  1925. __docker_subcommand && ret=0
  1926. ;;
  1927. esac
  1928. return ret
  1929. }
  1930. _dockerd() {
  1931. integer ret=1
  1932. words[1]='daemon'
  1933. __docker_subcommand && ret=0
  1934. return ret
  1935. }
  1936. _docker "$@"
  1937. # Local Variables:
  1938. # mode: Shell-Script
  1939. # sh-indentation: 4
  1940. # indent-tabs-mode: nil
  1941. # sh-basic-offset: 4
  1942. # End:
  1943. # vim: ft=zsh sw=4 ts=4 et