docker 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103
  1. #!/bin/bash
  2. #
  3. # bash completion file for core docker commands
  4. #
  5. # This script provides completion of:
  6. # - commands and their options
  7. # - container ids and names
  8. # - image repos and tags
  9. # - filepaths
  10. #
  11. # To enable the completions either:
  12. # - place this file in /etc/bash_completion.d
  13. # or
  14. # - copy this file to e.g. ~/.docker-completion.sh and add the line
  15. # below to your .bashrc after bash completion features are loaded
  16. # . ~/.docker-completion.sh
  17. #
  18. # Configuration:
  19. #
  20. # For several commands, the amount of completions can be configured by
  21. # setting environment variables.
  22. #
  23. # DOCKER_COMPLETION_SHOW_CONTAINER_IDS
  24. # DOCKER_COMPLETION_SHOW_NETWORK_IDS
  25. # DOCKER_COMPLETION_SHOW_NODE_IDS
  26. # DOCKER_COMPLETION_SHOW_PLUGIN_IDS
  27. # DOCKER_COMPLETION_SHOW_SECRET_IDS
  28. # DOCKER_COMPLETION_SHOW_SERVICE_IDS
  29. # "no" - Show names only (default)
  30. # "yes" - Show names and ids
  31. #
  32. # You can tailor completion for the "events", "history", "inspect", "run",
  33. # "rmi" and "save" commands by settings the following environment
  34. # variables:
  35. #
  36. # DOCKER_COMPLETION_SHOW_IMAGE_IDS
  37. # "none" - Show names only (default)
  38. # "non-intermediate" - Show names and ids, but omit intermediate image IDs
  39. # "all" - Show names and ids, including intermediate image IDs
  40. #
  41. # DOCKER_COMPLETION_SHOW_TAGS
  42. # "yes" - include tags in completion options (default)
  43. # "no" - don't include tags in completion options
  44. #
  45. # Note:
  46. # Currently, the completions will not work if the docker daemon is not
  47. # bound to the default communication port/socket
  48. # If the docker daemon is using a unix socket for communication your user
  49. # must have access to the socket for the completions to function correctly
  50. #
  51. # Note for developers:
  52. # Please arrange options sorted alphabetically by long name with the short
  53. # options immediately following their corresponding long form.
  54. # This order should be applied to lists, alternatives and code blocks.
  55. __docker_previous_extglob_setting=$(shopt -p extglob)
  56. shopt -s extglob
  57. __docker_q() {
  58. docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
  59. }
  60. # __docker_containers returns a list of containers. Additional options to
  61. # `docker ps` may be specified in order to filter the list, e.g.
  62. # `__docker_containers --filter status=running`
  63. # By default, only names are returned.
  64. # Set DOCKER_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs.
  65. # An optional first option `--id|--name` may be used to limit the
  66. # output to the IDs or names of matching items. This setting takes
  67. # precedence over the environment setting.
  68. __docker_containers() {
  69. local format
  70. if [ "$1" = "--id" ] ; then
  71. format='{{.ID}}'
  72. shift
  73. elif [ "$1" = "--name" ] ; then
  74. format='{{.Names}}'
  75. shift
  76. elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS}" = yes ] ; then
  77. format='{{.ID}} {{.Names}}'
  78. else
  79. format='{{.Names}}'
  80. fi
  81. __docker_q ps --format "$format" "$@"
  82. }
  83. # __docker_complete_containers applies completion of containers based on the current
  84. # value of `$cur` or the value of the optional first option `--cur`, if given.
  85. # Additional filters may be appended, see `__docker_containers`.
  86. __docker_complete_containers() {
  87. local current="$cur"
  88. if [ "$1" = "--cur" ] ; then
  89. current="$2"
  90. shift 2
  91. fi
  92. COMPREPLY=( $(compgen -W "$(__docker_containers "$@")" -- "$current") )
  93. }
  94. __docker_complete_containers_all() {
  95. __docker_complete_containers "$@" --all
  96. }
  97. __docker_complete_containers_running() {
  98. __docker_complete_containers "$@" --filter status=running
  99. }
  100. __docker_complete_containers_stopped() {
  101. __docker_complete_containers "$@" --filter status=exited
  102. }
  103. __docker_complete_containers_unpauseable() {
  104. __docker_complete_containers "$@" --filter status=paused
  105. }
  106. __docker_complete_container_names() {
  107. local containers=( $(__docker_q ps -aq --no-trunc) )
  108. local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
  109. names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
  110. COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
  111. }
  112. __docker_complete_container_ids() {
  113. local containers=( $(__docker_q ps -aq) )
  114. COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
  115. }
  116. __docker_images() {
  117. local images_args=""
  118. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  119. all)
  120. images_args="--no-trunc -a"
  121. ;;
  122. non-intermediate)
  123. images_args="--no-trunc"
  124. ;;
  125. esac
  126. local repo_print_command
  127. if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
  128. repo_print_command='print $1; print $1":"$2'
  129. else
  130. repo_print_command='print $1'
  131. fi
  132. local awk_script
  133. case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
  134. all|non-intermediate)
  135. awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }'
  136. ;;
  137. none|*)
  138. awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }'
  139. ;;
  140. esac
  141. __docker_q images $images_args | awk "$awk_script" | grep -v '<none>$'
  142. }
  143. __docker_complete_images() {
  144. COMPREPLY=( $(compgen -W "$(__docker_images)" -- "$cur") )
  145. __ltrim_colon_completions "$cur"
  146. }
  147. __docker_complete_image_repos() {
  148. local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
  149. COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
  150. }
  151. __docker_complete_image_repos_and_tags() {
  152. local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')"
  153. COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") )
  154. __ltrim_colon_completions "$cur"
  155. }
  156. # __docker_networks returns a list of all networks. Additional options to
  157. # `docker network ls` may be specified in order to filter the list, e.g.
  158. # `__docker_networks --filter type=custom`
  159. # By default, only names are returned.
  160. # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete IDs.
  161. # An optional first option `--id|--name` may be used to limit the
  162. # output to the IDs or names of matching items. This setting takes
  163. # precedence over the environment setting.
  164. __docker_networks() {
  165. local format
  166. if [ "$1" = "--id" ] ; then
  167. format='{{.ID}}'
  168. shift
  169. elif [ "$1" = "--name" ] ; then
  170. format='{{.Name}}'
  171. shift
  172. elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] ; then
  173. format='{{.ID}} {{.Name}}'
  174. else
  175. format='{{.Name}}'
  176. fi
  177. __docker_q network ls --format "$format" "$@"
  178. }
  179. # __docker_complete_networks applies completion of networks based on the current
  180. # value of `$cur` or the value of the optional first option `--cur`, if given.
  181. # Additional filters may be appended, see `__docker_networks`.
  182. __docker_complete_networks() {
  183. local current="$cur"
  184. if [ "$1" = "--cur" ] ; then
  185. current="$2"
  186. shift 2
  187. fi
  188. COMPREPLY=( $(compgen -W "$(__docker_networks "$@")" -- "$current") )
  189. }
  190. __docker_complete_containers_in_network() {
  191. local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1")
  192. COMPREPLY=( $(compgen -W "$containers" -- "$cur") )
  193. }
  194. # __docker_volumes returns a list of all volumes. Additional options to
  195. # `docker volume ls` may be specified in order to filter the list, e.g.
  196. # `__docker_volumes --filter dangling=true`
  197. # Because volumes do not have IDs, this function does not distinguish between
  198. # IDs and names.
  199. __docker_volumes() {
  200. __docker_q volume ls -q "$@"
  201. }
  202. # __docker_complete_volumes applies completion of volumes based on the current
  203. # value of `$cur` or the value of the optional first option `--cur`, if given.
  204. # Additional filters may be appended, see `__docker_volumes`.
  205. __docker_complete_volumes() {
  206. local current="$cur"
  207. if [ "$1" = "--cur" ] ; then
  208. current="$2"
  209. shift 2
  210. fi
  211. COMPREPLY=( $(compgen -W "$(__docker_volumes "$@")" -- "$current") )
  212. }
  213. # __docker_plugins_bundled returns a list of all plugins of a given type.
  214. # The type has to be specified with the mandatory option `--type`.
  215. # Valid types are: Network, Volume, Authorization.
  216. # Completions may be added or removed with `--add` and `--remove`
  217. # This function only deals with plugins that come bundled with Docker.
  218. # For plugins managed by `docker plugin`, see `__docker_plugins_installed`.
  219. __docker_plugins_bundled() {
  220. local type add=() remove=()
  221. while true ; do
  222. case "$1" in
  223. --type)
  224. type="$2"
  225. shift 2
  226. ;;
  227. --add)
  228. add+=("$2")
  229. shift 2
  230. ;;
  231. --remove)
  232. remove+=("$2")
  233. shift 2
  234. ;;
  235. *)
  236. break
  237. ;;
  238. esac
  239. done
  240. local plugins=($(__docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $type: //p"))
  241. for del in "${remove[@]}" ; do
  242. plugins=(${plugins[@]/$del/})
  243. done
  244. echo "${plugins[@]} ${add[@]}"
  245. }
  246. # __docker_complete_plugins_bundled applies completion of plugins based on the current
  247. # value of `$cur` or the value of the optional first option `--cur`, if given.
  248. # The plugin type has to be specified with the next option `--type`.
  249. # This function only deals with plugins that come bundled with Docker.
  250. # For completion of plugins managed by `docker plugin`, see
  251. # `__docker_complete_plugins_installed`.
  252. __docker_complete_plugins_bundled() {
  253. local current="$cur"
  254. if [ "$1" = "--cur" ] ; then
  255. current="$2"
  256. shift 2
  257. fi
  258. COMPREPLY=( $(compgen -W "$(__docker_plugins_bundled "$@")" -- "$current") )
  259. }
  260. # __docker_plugins_installed returns a list of all plugins that were installed with
  261. # the Docker plugin API.
  262. # By default, only names are returned.
  263. # Set DOCKER_COMPLETION_SHOW_PLUGIN_IDS=yes to also complete IDs.
  264. # For built-in pugins, see `__docker_plugins_bundled`.
  265. __docker_plugins_installed() {
  266. local fields
  267. if [ "$DOCKER_COMPLETION_SHOW_PLUGIN_IDS" = yes ] ; then
  268. fields='$1,$2'
  269. else
  270. fields='$2'
  271. fi
  272. __docker_q plugin ls | awk "NR>1 {print $fields}"
  273. }
  274. # __docker_complete_plugins_installed applies completion of plugins that were installed
  275. # with the Docker plugin API, based on the current value of `$cur` or the value of
  276. # the optional first option `--cur`, if given.
  277. # For completion of built-in pugins, see `__docker_complete_plugins_bundled`.
  278. __docker_complete_plugins_installed() {
  279. local current="$cur"
  280. if [ "$1" = "--cur" ] ; then
  281. current="$2"
  282. shift 2
  283. fi
  284. COMPREPLY=( $(compgen -W "$(__docker_plugins_installed "$@")" -- "$current") )
  285. }
  286. __docker_runtimes() {
  287. __docker_q info | sed -n 's/^Runtimes: \(.*\)/\1/p'
  288. }
  289. __docker_complete_runtimes() {
  290. COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") )
  291. }
  292. # __docker_secrets returns a list of all secrets.
  293. # By default, only names of secrets are returned.
  294. # Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs of secrets.
  295. __docker_secrets() {
  296. local fields='$2' # default: name only
  297. [ "${DOCKER_COMPLETION_SHOW_SECRET_IDS}" = yes ] && fields='$1,$2' # ID and name
  298. __docker_q secret ls | awk "NR>1 {print $fields}"
  299. }
  300. # __docker_complete_secrets applies completion of secrets based on the current value
  301. # of `$cur`.
  302. __docker_complete_secrets() {
  303. COMPREPLY=( $(compgen -W "$(__docker_secrets)" -- "$cur") )
  304. }
  305. # __docker_stacks returns a list of all stacks.
  306. __docker_stacks() {
  307. __docker_q stack ls | awk 'NR>1 {print $1}'
  308. }
  309. # __docker_complete_stacks applies completion of stacks based on the current value
  310. # of `$cur` or the value of the optional first option `--cur`, if given.
  311. __docker_complete_stacks() {
  312. local current="$cur"
  313. if [ "$1" = "--cur" ] ; then
  314. current="$2"
  315. shift 2
  316. fi
  317. COMPREPLY=( $(compgen -W "$(__docker_stacks "$@")" -- "$current") )
  318. }
  319. # __docker_nodes returns a list of all nodes. Additional options to
  320. # `docker node ls` may be specified in order to filter the list, e.g.
  321. # `__docker_nodes --filter role=manager`
  322. # By default, only node names are returned.
  323. # Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs.
  324. # An optional first option `--id|--name` may be used to limit the
  325. # output to the IDs or names of matching items. This setting takes
  326. # precedence over the environment setting.
  327. __docker_nodes() {
  328. local fields='$2' # default: node name only
  329. [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name
  330. if [ "$1" = "--id" ] ; then
  331. fields='$1' # IDs only
  332. shift
  333. elif [ "$1" = "--name" ] ; then
  334. fields='$2' # names only
  335. shift
  336. fi
  337. __docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}"
  338. }
  339. # __docker_complete_nodes applies completion of nodes based on the current
  340. # value of `$cur` or the value of the optional first option `--cur`, if given.
  341. # Additional filters may be appended, see `__docker_nodes`.
  342. __docker_complete_nodes() {
  343. local current="$cur"
  344. if [ "$1" = "--cur" ] ; then
  345. current="$2"
  346. shift 2
  347. fi
  348. COMPREPLY=( $(compgen -W "$(__docker_nodes "$@")" -- "$current") )
  349. }
  350. __docker_complete_nodes_plus_self() {
  351. __docker_complete_nodes "$@"
  352. COMPREPLY+=( self )
  353. }
  354. # __docker_services returns a list of all services. Additional options to
  355. # `docker service ls` may be specified in order to filter the list, e.g.
  356. # `__docker_services --filter name=xxx`
  357. # By default, only node names are returned.
  358. # Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete IDs.
  359. # An optional first option `--id|--name` may be used to limit the
  360. # output to the IDs or names of matching items. This setting takes
  361. # precedence over the environment setting.
  362. __docker_services() {
  363. local fields='$2' # default: service name only
  364. [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name
  365. if [ "$1" = "--id" ] ; then
  366. fields='$1' # IDs only
  367. shift
  368. elif [ "$1" = "--name" ] ; then
  369. fields='$2' # names only
  370. shift
  371. fi
  372. __docker_q service ls "$@" | awk "NR>1 {print $fields}"
  373. }
  374. # __docker_complete_services applies completion of services based on the current
  375. # value of `$cur` or the value of the optional first option `--cur`, if given.
  376. # Additional filters may be appended, see `__docker_services`.
  377. __docker_complete_services() {
  378. local current="$cur"
  379. if [ "$1" = "--cur" ] ; then
  380. current="$2"
  381. shift 2
  382. fi
  383. COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") )
  384. }
  385. # __docker_append_to_completions appends the word passed as an argument to every
  386. # word in `$COMPREPLY`.
  387. # Normally you do this with `compgen -S` while generating the completions.
  388. # This function allows you to append a suffix later. It allows you to use
  389. # the __docker_complete_XXX functions in cases where you need a suffix.
  390. __docker_append_to_completions() {
  391. COMPREPLY=( ${COMPREPLY[@]/%/"$1"} )
  392. }
  393. # __docker_is_experimental tests whether the currently configured Docker daemon
  394. # runs in experimental mode. If so, the function exits with 0 (true).
  395. # Otherwise, or if the result cannot be determined, the exit value is 1 (false).
  396. __docker_is_experimental() {
  397. [ "$(__docker_q version -f '{{.Server.Experimental}}')" = "true" ]
  398. }
  399. # __docker_pos_first_nonflag finds the position of the first word that is neither
  400. # option nor an option's argument. If there are options that require arguments,
  401. # you should pass a glob describing those options, e.g. "--option1|-o|--option2"
  402. # Use this function to restrict completions to exact positions after the argument list.
  403. __docker_pos_first_nonflag() {
  404. local argument_flags=$1
  405. local counter=$((${subcommand_pos:-${command_pos}} + 1))
  406. while [ $counter -le $cword ]; do
  407. if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
  408. (( counter++ ))
  409. # eat "=" in case of --option=arg syntax
  410. [ "${words[$counter]}" = "=" ] && (( counter++ ))
  411. else
  412. case "${words[$counter]}" in
  413. -*)
  414. ;;
  415. *)
  416. break
  417. ;;
  418. esac
  419. fi
  420. # Bash splits words at "=", retaining "=" as a word, examples:
  421. # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
  422. while [ "${words[$counter + 1]}" = "=" ] ; do
  423. counter=$(( counter + 2))
  424. done
  425. (( counter++ ))
  426. done
  427. echo $counter
  428. }
  429. # __docker_map_key_of_current_option returns `key` if we are currently completing the
  430. # value of a map option (`key=value`) which matches the extglob given as an argument.
  431. # This function is needed for key-specific completions.
  432. __docker_map_key_of_current_option() {
  433. local glob="$1"
  434. local key glob_pos
  435. if [ "$cur" = "=" ] ; then # key= case
  436. key="$prev"
  437. glob_pos=$((cword - 2))
  438. elif [[ $cur == *=* ]] ; then # key=value case (OSX)
  439. key=${cur%=*}
  440. glob_pos=$((cword - 1))
  441. elif [ "$prev" = "=" ] ; then
  442. key=${words[$cword - 2]} # key=value case
  443. glob_pos=$((cword - 3))
  444. else
  445. return
  446. fi
  447. [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
  448. [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
  449. }
  450. # __docker_value_of_option returns the value of the first option matching `option_glob`.
  451. # Valid values for `option_glob` are option names like `--log-level` and globs like
  452. # `--log-level|-l`
  453. # Only positions between the command and the current word are considered.
  454. __docker_value_of_option() {
  455. local option_extglob=$(__docker_to_extglob "$1")
  456. local counter=$((command_pos + 1))
  457. while [ $counter -lt $cword ]; do
  458. case ${words[$counter]} in
  459. $option_extglob )
  460. echo ${words[$counter + 1]}
  461. break
  462. ;;
  463. esac
  464. (( counter++ ))
  465. done
  466. }
  467. # __docker_to_alternatives transforms a multiline list of strings into a single line
  468. # string with the words separated by `|`.
  469. # This is used to prepare arguments to __docker_pos_first_nonflag().
  470. __docker_to_alternatives() {
  471. local parts=( $1 )
  472. local IFS='|'
  473. echo "${parts[*]}"
  474. }
  475. # __docker_to_extglob transforms a multiline list of options into an extglob pattern
  476. # suitable for use in case statements.
  477. __docker_to_extglob() {
  478. local extglob=$( __docker_to_alternatives "$1" )
  479. echo "@($extglob)"
  480. }
  481. # __docker_subcommands processes subcommands
  482. # Locates the first occurrence of any of the subcommands contained in the
  483. # first argument. In case of a match, calls the corresponding completion
  484. # function and returns 0.
  485. # If no match is found, 1 is returned. The calling function can then
  486. # continue processing its completion.
  487. #
  488. # TODO if the preceding command has options that accept arguments and an
  489. # argument is equal ot one of the subcommands, this is falsely detected as
  490. # a match.
  491. __docker_subcommands() {
  492. local subcommands="$1"
  493. local counter=$(($command_pos + 1))
  494. while [ $counter -lt $cword ]; do
  495. case "${words[$counter]}" in
  496. $(__docker_to_extglob "$subcommands") )
  497. subcommand_pos=$counter
  498. local subcommand=${words[$counter]}
  499. local completions_func=_docker_${command}_${subcommand}
  500. declare -F $completions_func >/dev/null && $completions_func
  501. return 0
  502. ;;
  503. esac
  504. (( counter++ ))
  505. done
  506. return 1
  507. }
  508. # __docker_nospace suppresses trailing whitespace
  509. __docker_nospace() {
  510. # compopt is not available in ancient bash versions
  511. type compopt &>/dev/null && compopt -o nospace
  512. }
  513. __docker_complete_resolved_hostname() {
  514. command -v host >/dev/null 2>&1 || return
  515. COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
  516. }
  517. __docker_local_interfaces() {
  518. command -v ip >/dev/null 2>&1 || return
  519. ip addr show scope global 2>/dev/null | sed -n 's| \+inet \([0-9.]\+\).* \([^ ]\+\)|\1 \2|p'
  520. }
  521. __docker_complete_local_interfaces() {
  522. local additional_interface
  523. if [ "$1" = "--add" ] ; then
  524. additional_interface="$2"
  525. fi
  526. COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) )
  527. }
  528. __docker_complete_capabilities() {
  529. # The list of capabilities is defined in types.go, ALL was added manually.
  530. COMPREPLY=( $( compgen -W "
  531. ALL
  532. AUDIT_CONTROL
  533. AUDIT_WRITE
  534. AUDIT_READ
  535. BLOCK_SUSPEND
  536. CHOWN
  537. DAC_OVERRIDE
  538. DAC_READ_SEARCH
  539. FOWNER
  540. FSETID
  541. IPC_LOCK
  542. IPC_OWNER
  543. KILL
  544. LEASE
  545. LINUX_IMMUTABLE
  546. MAC_ADMIN
  547. MAC_OVERRIDE
  548. MKNOD
  549. NET_ADMIN
  550. NET_BIND_SERVICE
  551. NET_BROADCAST
  552. NET_RAW
  553. SETFCAP
  554. SETGID
  555. SETPCAP
  556. SETUID
  557. SYS_ADMIN
  558. SYS_BOOT
  559. SYS_CHROOT
  560. SYSLOG
  561. SYS_MODULE
  562. SYS_NICE
  563. SYS_PACCT
  564. SYS_PTRACE
  565. SYS_RAWIO
  566. SYS_RESOURCE
  567. SYS_TIME
  568. SYS_TTY_CONFIG
  569. WAKE_ALARM
  570. " -- "$cur" ) )
  571. }
  572. __docker_complete_detach-keys() {
  573. case "$prev" in
  574. --detach-keys)
  575. case "$cur" in
  576. *,)
  577. COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
  578. ;;
  579. *)
  580. COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
  581. ;;
  582. esac
  583. __docker_nospace
  584. return
  585. ;;
  586. esac
  587. return 1
  588. }
  589. __docker_complete_isolation() {
  590. COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
  591. }
  592. __docker_complete_log_drivers() {
  593. COMPREPLY=( $( compgen -W "
  594. awslogs
  595. etwlogs
  596. fluentd
  597. gcplogs
  598. gelf
  599. journald
  600. json-file
  601. logentries
  602. none
  603. splunk
  604. syslog
  605. " -- "$cur" ) )
  606. }
  607. __docker_complete_log_options() {
  608. # see docs/reference/logging/index.md
  609. local awslogs_options="awslogs-region awslogs-group awslogs-stream"
  610. local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag"
  611. local gcplogs_options="env gcp-log-cmd gcp-project labels"
  612. local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag"
  613. local journald_options="env labels tag"
  614. local json_file_options="env labels max-file max-size"
  615. local logentries_options="logentries-token"
  616. local 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"
  617. local splunk_options="env labels 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"
  618. local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $logentries_options $json_file_options $syslog_options $splunk_options"
  619. case $(__docker_value_of_option --log-driver) in
  620. '')
  621. COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) )
  622. ;;
  623. awslogs)
  624. COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) )
  625. ;;
  626. fluentd)
  627. COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) )
  628. ;;
  629. gcplogs)
  630. COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) )
  631. ;;
  632. gelf)
  633. COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) )
  634. ;;
  635. journald)
  636. COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) )
  637. ;;
  638. json-file)
  639. COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) )
  640. ;;
  641. logentries)
  642. COMPREPLY=( $( compgen -W "$logentries_options" -S = -- "$cur" ) )
  643. ;;
  644. syslog)
  645. COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) )
  646. ;;
  647. splunk)
  648. COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) )
  649. ;;
  650. *)
  651. return
  652. ;;
  653. esac
  654. __docker_nospace
  655. }
  656. __docker_complete_log_driver_options() {
  657. local key=$(__docker_map_key_of_current_option '--log-opt')
  658. case "$key" in
  659. fluentd-async-connect)
  660. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  661. return
  662. ;;
  663. gelf-address)
  664. COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) )
  665. __docker_nospace
  666. return
  667. ;;
  668. gelf-compression-level)
  669. COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) )
  670. return
  671. ;;
  672. gelf-compression-type)
  673. COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) )
  674. return
  675. ;;
  676. syslog-address)
  677. COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) )
  678. __docker_nospace
  679. __ltrim_colon_completions "${cur}"
  680. return
  681. ;;
  682. syslog-facility)
  683. COMPREPLY=( $( compgen -W "
  684. auth
  685. authpriv
  686. cron
  687. daemon
  688. ftp
  689. kern
  690. local0
  691. local1
  692. local2
  693. local3
  694. local4
  695. local5
  696. local6
  697. local7
  698. lpr
  699. mail
  700. news
  701. syslog
  702. user
  703. uucp
  704. " -- "${cur##*=}" ) )
  705. return
  706. ;;
  707. syslog-format)
  708. COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) )
  709. return
  710. ;;
  711. syslog-tls-ca-cert|syslog-tls-cert|syslog-tls-key)
  712. _filedir
  713. return
  714. ;;
  715. syslog-tls-skip-verify)
  716. COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) )
  717. return
  718. ;;
  719. splunk-url)
  720. COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) )
  721. __docker_nospace
  722. __ltrim_colon_completions "${cur}"
  723. return
  724. ;;
  725. splunk-gzip|splunk-insecureskipverify|splunk-verify-connection)
  726. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  727. return
  728. ;;
  729. splunk-format)
  730. COMPREPLY=( $( compgen -W "inline json raw" -- "${cur##*=}" ) )
  731. return
  732. ;;
  733. esac
  734. return 1
  735. }
  736. __docker_complete_log_levels() {
  737. COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) )
  738. }
  739. __docker_complete_restart() {
  740. case "$prev" in
  741. --restart)
  742. case "$cur" in
  743. on-failure:*)
  744. ;;
  745. *)
  746. COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") )
  747. ;;
  748. esac
  749. return
  750. ;;
  751. esac
  752. return 1
  753. }
  754. # __docker_complete_signals returns a subset of the available signals that is most likely
  755. # relevant in the context of docker containers
  756. __docker_complete_signals() {
  757. local signals=(
  758. SIGCONT
  759. SIGHUP
  760. SIGINT
  761. SIGKILL
  762. SIGQUIT
  763. SIGSTOP
  764. SIGTERM
  765. SIGUSR1
  766. SIGUSR2
  767. )
  768. COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) )
  769. }
  770. __docker_complete_user_group() {
  771. if [[ $cur == *:* ]] ; then
  772. COMPREPLY=( $(compgen -g -- "${cur#*:}") )
  773. else
  774. COMPREPLY=( $(compgen -u -S : -- "$cur") )
  775. __docker_nospace
  776. fi
  777. }
  778. _docker_docker() {
  779. # global options that may appear after the docker command
  780. local boolean_options="
  781. $global_boolean_options
  782. --help
  783. --version -v
  784. "
  785. case "$prev" in
  786. --config)
  787. _filedir -d
  788. return
  789. ;;
  790. --log-level|-l)
  791. __docker_complete_log_levels
  792. return
  793. ;;
  794. $(__docker_to_extglob "$global_options_with_args") )
  795. return
  796. ;;
  797. esac
  798. case "$cur" in
  799. -*)
  800. COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) )
  801. ;;
  802. *)
  803. local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" )
  804. if [ $cword -eq $counter ]; then
  805. __docker_is_experimental && commands+=(${experimental_commands[*]})
  806. COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
  807. fi
  808. ;;
  809. esac
  810. }
  811. _docker_attach() {
  812. _docker_container_attach
  813. }
  814. _docker_build() {
  815. _docker_image_build
  816. }
  817. _docker_container() {
  818. local subcommands="
  819. attach
  820. commit
  821. cp
  822. create
  823. diff
  824. exec
  825. export
  826. inspect
  827. kill
  828. logs
  829. ls
  830. pause
  831. port
  832. prune
  833. rename
  834. restart
  835. rm
  836. run
  837. start
  838. stats
  839. stop
  840. top
  841. unpause
  842. update
  843. wait
  844. "
  845. local aliases="
  846. list
  847. ps
  848. "
  849. __docker_subcommands "$subcommands $aliases" && return
  850. case "$cur" in
  851. -*)
  852. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  853. ;;
  854. *)
  855. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  856. ;;
  857. esac
  858. }
  859. _docker_container_attach() {
  860. __docker_complete_detach-keys && return
  861. case "$cur" in
  862. -*)
  863. COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) )
  864. ;;
  865. *)
  866. local counter=$(__docker_pos_first_nonflag '--detach-keys')
  867. if [ $cword -eq $counter ]; then
  868. __docker_complete_containers_running
  869. fi
  870. ;;
  871. esac
  872. }
  873. _docker_container_commit() {
  874. case "$prev" in
  875. --author|-a|--change|-c|--message|-m)
  876. return
  877. ;;
  878. esac
  879. case "$cur" in
  880. -*)
  881. COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) )
  882. ;;
  883. *)
  884. local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m')
  885. if [ $cword -eq $counter ]; then
  886. __docker_complete_containers_all
  887. return
  888. fi
  889. (( counter++ ))
  890. if [ $cword -eq $counter ]; then
  891. __docker_complete_image_repos_and_tags
  892. return
  893. fi
  894. ;;
  895. esac
  896. }
  897. _docker_container_cp() {
  898. case "$cur" in
  899. -*)
  900. COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) )
  901. ;;
  902. *)
  903. local counter=$(__docker_pos_first_nonflag)
  904. if [ $cword -eq $counter ]; then
  905. case "$cur" in
  906. *:)
  907. return
  908. ;;
  909. *)
  910. # combined container and filename completion
  911. _filedir
  912. local files=( ${COMPREPLY[@]} )
  913. __docker_complete_containers_all
  914. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  915. local containers=( ${COMPREPLY[@]} )
  916. COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) )
  917. if [[ "$COMPREPLY" == *: ]]; then
  918. __docker_nospace
  919. fi
  920. return
  921. ;;
  922. esac
  923. fi
  924. (( counter++ ))
  925. if [ $cword -eq $counter ]; then
  926. if [ -e "$prev" ]; then
  927. __docker_complete_containers_all
  928. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  929. __docker_nospace
  930. else
  931. _filedir
  932. fi
  933. return
  934. fi
  935. ;;
  936. esac
  937. }
  938. _docker_container_create() {
  939. _docker_container_run
  940. }
  941. _docker_container_diff() {
  942. case "$cur" in
  943. -*)
  944. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  945. ;;
  946. *)
  947. local counter=$(__docker_pos_first_nonflag)
  948. if [ $cword -eq $counter ]; then
  949. __docker_complete_containers_all
  950. fi
  951. ;;
  952. esac
  953. }
  954. _docker_container_exec() {
  955. __docker_complete_detach-keys && return
  956. case "$prev" in
  957. --env|-e)
  958. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  959. COMPREPLY=( $( compgen -e -- "$cur" ) )
  960. __docker_nospace
  961. return
  962. ;;
  963. --user|-u)
  964. __docker_complete_user_group
  965. return
  966. ;;
  967. esac
  968. case "$cur" in
  969. -*)
  970. COMPREPLY=( $( compgen -W "--detach -d --detach-keys --env -e --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
  971. ;;
  972. *)
  973. __docker_complete_containers_running
  974. ;;
  975. esac
  976. }
  977. _docker_container_export() {
  978. case "$prev" in
  979. --output|-o)
  980. _filedir
  981. return
  982. ;;
  983. esac
  984. case "$cur" in
  985. -*)
  986. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  987. ;;
  988. *)
  989. local counter=$(__docker_pos_first_nonflag)
  990. if [ $cword -eq $counter ]; then
  991. __docker_complete_containers_all
  992. fi
  993. ;;
  994. esac
  995. }
  996. _docker_container_inspect() {
  997. _docker_inspect --type container
  998. }
  999. _docker_container_kill() {
  1000. case "$prev" in
  1001. --signal|-s)
  1002. __docker_complete_signals
  1003. return
  1004. ;;
  1005. esac
  1006. case "$cur" in
  1007. -*)
  1008. COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) )
  1009. ;;
  1010. *)
  1011. __docker_complete_containers_running
  1012. ;;
  1013. esac
  1014. }
  1015. _docker_container_logs() {
  1016. case "$prev" in
  1017. --since|--tail)
  1018. return
  1019. ;;
  1020. esac
  1021. case "$cur" in
  1022. -*)
  1023. COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) )
  1024. ;;
  1025. *)
  1026. local counter=$(__docker_pos_first_nonflag '--since|--tail')
  1027. if [ $cword -eq $counter ]; then
  1028. __docker_complete_containers_all
  1029. fi
  1030. ;;
  1031. esac
  1032. }
  1033. _docker_container_list() {
  1034. _docker_container_ls
  1035. }
  1036. _docker_container_ls() {
  1037. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1038. case "$key" in
  1039. ancestor)
  1040. cur="${cur##*=}"
  1041. __docker_complete_images
  1042. return
  1043. ;;
  1044. before)
  1045. __docker_complete_containers_all --cur "${cur##*=}"
  1046. return
  1047. ;;
  1048. id)
  1049. __docker_complete_containers_all --cur "${cur##*=}" --id
  1050. return
  1051. ;;
  1052. health)
  1053. COMPREPLY=( $( compgen -W "healthy starting none unhealthy" -- "${cur##*=}" ) )
  1054. return
  1055. ;;
  1056. is-task)
  1057. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  1058. return
  1059. ;;
  1060. name)
  1061. __docker_complete_containers_all --cur "${cur##*=}" --name
  1062. return
  1063. ;;
  1064. network)
  1065. __docker_complete_networks --cur "${cur##*=}"
  1066. return
  1067. ;;
  1068. since)
  1069. __docker_complete_containers_all --cur "${cur##*=}"
  1070. return
  1071. ;;
  1072. status)
  1073. COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) )
  1074. return
  1075. ;;
  1076. volume)
  1077. __docker_complete_volumes --cur "${cur##*=}"
  1078. return
  1079. ;;
  1080. esac
  1081. case "$prev" in
  1082. --filter|-f)
  1083. COMPREPLY=( $( compgen -S = -W "ancestor before exited health id is-task label name network since status volume" -- "$cur" ) )
  1084. __docker_nospace
  1085. return
  1086. ;;
  1087. --format|--last|-n)
  1088. return
  1089. ;;
  1090. esac
  1091. case "$cur" in
  1092. -*)
  1093. COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) )
  1094. ;;
  1095. esac
  1096. }
  1097. _docker_container_pause() {
  1098. case "$cur" in
  1099. -*)
  1100. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1101. ;;
  1102. *)
  1103. __docker_complete_containers_running
  1104. ;;
  1105. esac
  1106. }
  1107. _docker_container_port() {
  1108. case "$cur" in
  1109. -*)
  1110. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1111. ;;
  1112. *)
  1113. local counter=$(__docker_pos_first_nonflag)
  1114. if [ $cword -eq $counter ]; then
  1115. __docker_complete_containers_all
  1116. fi
  1117. ;;
  1118. esac
  1119. }
  1120. _docker_container_prune() {
  1121. case "$cur" in
  1122. -*)
  1123. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  1124. ;;
  1125. esac
  1126. }
  1127. _docker_container_ps() {
  1128. _docker_container_ls
  1129. }
  1130. _docker_container_rename() {
  1131. case "$cur" in
  1132. -*)
  1133. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1134. ;;
  1135. *)
  1136. local counter=$(__docker_pos_first_nonflag)
  1137. if [ $cword -eq $counter ]; then
  1138. __docker_complete_containers_all
  1139. fi
  1140. ;;
  1141. esac
  1142. }
  1143. _docker_container_restart() {
  1144. case "$prev" in
  1145. --time|-t)
  1146. return
  1147. ;;
  1148. esac
  1149. case "$cur" in
  1150. -*)
  1151. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1152. ;;
  1153. *)
  1154. __docker_complete_containers_all
  1155. ;;
  1156. esac
  1157. }
  1158. _docker_container_rm() {
  1159. case "$cur" in
  1160. -*)
  1161. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1162. ;;
  1163. *)
  1164. for arg in "${COMP_WORDS[@]}"; do
  1165. case "$arg" in
  1166. --force|-f)
  1167. __docker_complete_containers_all
  1168. return
  1169. ;;
  1170. esac
  1171. done
  1172. __docker_complete_containers_stopped
  1173. ;;
  1174. esac
  1175. }
  1176. _docker_container_run() {
  1177. local options_with_args="
  1178. --add-host
  1179. --attach -a
  1180. --blkio-weight
  1181. --blkio-weight-device
  1182. --cap-add
  1183. --cap-drop
  1184. --cgroup-parent
  1185. --cidfile
  1186. --cpu-period
  1187. --cpu-quota
  1188. --cpu-rt-period
  1189. --cpu-rt-runtime
  1190. --cpuset-cpus
  1191. --cpus
  1192. --cpuset-mems
  1193. --cpu-shares -c
  1194. --device
  1195. --device-read-bps
  1196. --device-read-iops
  1197. --device-write-bps
  1198. --device-write-iops
  1199. --dns
  1200. --dns-option
  1201. --dns-search
  1202. --entrypoint
  1203. --env -e
  1204. --env-file
  1205. --expose
  1206. --group-add
  1207. --hostname -h
  1208. --ip
  1209. --ip6
  1210. --ipc
  1211. --isolation
  1212. --kernel-memory
  1213. --label-file
  1214. --label -l
  1215. --link
  1216. --link-local-ip
  1217. --log-driver
  1218. --log-opt
  1219. --mac-address
  1220. --memory -m
  1221. --memory-swap
  1222. --memory-swappiness
  1223. --memory-reservation
  1224. --name
  1225. --network
  1226. --network-alias
  1227. --oom-score-adj
  1228. --pid
  1229. --pids-limit
  1230. --publish -p
  1231. --restart
  1232. --runtime
  1233. --security-opt
  1234. --shm-size
  1235. --stop-signal
  1236. --stop-timeout
  1237. --storage-opt
  1238. --tmpfs
  1239. --sysctl
  1240. --ulimit
  1241. --user -u
  1242. --userns
  1243. --uts
  1244. --volume-driver
  1245. --volumes-from
  1246. --volume -v
  1247. --workdir -w
  1248. "
  1249. local boolean_options="
  1250. --disable-content-trust=false
  1251. --help
  1252. --init
  1253. --interactive -i
  1254. --oom-kill-disable
  1255. --privileged
  1256. --publish-all -P
  1257. --read-only
  1258. --tty -t
  1259. "
  1260. if [ "$command" = "run" -o "$subcommand" = "run" ] ; then
  1261. options_with_args="$options_with_args
  1262. --detach-keys
  1263. --health-cmd
  1264. --health-interval
  1265. --health-retries
  1266. --health-timeout
  1267. "
  1268. boolean_options="$boolean_options
  1269. --detach -d
  1270. --no-healthcheck
  1271. --rm
  1272. --sig-proxy=false
  1273. "
  1274. __docker_complete_detach-keys && return
  1275. fi
  1276. local all_options="$options_with_args $boolean_options"
  1277. __docker_complete_log_driver_options && return
  1278. __docker_complete_restart && return
  1279. local key=$(__docker_map_key_of_current_option '--security-opt')
  1280. case "$key" in
  1281. label)
  1282. [[ $cur == *: ]] && return
  1283. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1284. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1285. __docker_nospace
  1286. fi
  1287. return
  1288. ;;
  1289. seccomp)
  1290. local cur=${cur##*=}
  1291. _filedir
  1292. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1293. return
  1294. ;;
  1295. esac
  1296. case "$prev" in
  1297. --add-host)
  1298. case "$cur" in
  1299. *:)
  1300. __docker_complete_resolved_hostname
  1301. return
  1302. ;;
  1303. esac
  1304. ;;
  1305. --attach|-a)
  1306. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1307. return
  1308. ;;
  1309. --cap-add|--cap-drop)
  1310. __docker_complete_capabilities
  1311. return
  1312. ;;
  1313. --cidfile|--env-file|--label-file)
  1314. _filedir
  1315. return
  1316. ;;
  1317. --device|--tmpfs|--volume|-v)
  1318. case "$cur" in
  1319. *:*)
  1320. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1321. ;;
  1322. '')
  1323. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1324. __docker_nospace
  1325. ;;
  1326. /*)
  1327. _filedir
  1328. __docker_nospace
  1329. ;;
  1330. esac
  1331. return
  1332. ;;
  1333. --env|-e)
  1334. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1335. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1336. __docker_nospace
  1337. return
  1338. ;;
  1339. --ipc)
  1340. case "$cur" in
  1341. *:*)
  1342. cur="${cur#*:}"
  1343. __docker_complete_containers_running
  1344. ;;
  1345. *)
  1346. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1347. if [ "$COMPREPLY" = "container:" ]; then
  1348. __docker_nospace
  1349. fi
  1350. ;;
  1351. esac
  1352. return
  1353. ;;
  1354. --isolation)
  1355. __docker_complete_isolation
  1356. return
  1357. ;;
  1358. --link)
  1359. case "$cur" in
  1360. *:*)
  1361. ;;
  1362. *)
  1363. __docker_complete_containers_running
  1364. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1365. __docker_nospace
  1366. ;;
  1367. esac
  1368. return
  1369. ;;
  1370. --log-driver)
  1371. __docker_complete_log_drivers
  1372. return
  1373. ;;
  1374. --log-opt)
  1375. __docker_complete_log_options
  1376. return
  1377. ;;
  1378. --network)
  1379. case "$cur" in
  1380. container:*)
  1381. __docker_complete_containers_all --cur "${cur#*:}"
  1382. ;;
  1383. *)
  1384. COMPREPLY=( $( compgen -W "$(__docker_plugins_bundled --type Network) $(__docker_networks) container:" -- "$cur") )
  1385. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1386. __docker_nospace
  1387. fi
  1388. ;;
  1389. esac
  1390. return
  1391. ;;
  1392. --pid)
  1393. case "$cur" in
  1394. *:*)
  1395. __docker_complete_containers_running --cur "${cur#*:}"
  1396. ;;
  1397. *)
  1398. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1399. if [ "$COMPREPLY" = "container:" ]; then
  1400. __docker_nospace
  1401. fi
  1402. ;;
  1403. esac
  1404. return
  1405. ;;
  1406. --runtime)
  1407. __docker_complete_runtimes
  1408. return
  1409. ;;
  1410. --security-opt)
  1411. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1412. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1413. __docker_nospace
  1414. fi
  1415. return
  1416. ;;
  1417. --storage-opt)
  1418. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  1419. __docker_nospace
  1420. return
  1421. ;;
  1422. --user|-u)
  1423. __docker_complete_user_group
  1424. return
  1425. ;;
  1426. --userns)
  1427. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1428. return
  1429. ;;
  1430. --volume-driver)
  1431. __docker_complete_plugins_bundled --type Volume
  1432. return
  1433. ;;
  1434. --volumes-from)
  1435. __docker_complete_containers_all
  1436. return
  1437. ;;
  1438. $(__docker_to_extglob "$options_with_args") )
  1439. return
  1440. ;;
  1441. esac
  1442. case "$cur" in
  1443. -*)
  1444. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1445. ;;
  1446. *)
  1447. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1448. if [ $cword -eq $counter ]; then
  1449. __docker_complete_images
  1450. fi
  1451. ;;
  1452. esac
  1453. }
  1454. _docker_container_start() {
  1455. __docker_complete_detach-keys && return
  1456. case "$cur" in
  1457. -*)
  1458. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  1459. ;;
  1460. *)
  1461. __docker_complete_containers_stopped
  1462. ;;
  1463. esac
  1464. }
  1465. _docker_container_stats() {
  1466. case "$prev" in
  1467. --format)
  1468. return
  1469. ;;
  1470. esac
  1471. case "$cur" in
  1472. -*)
  1473. COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) )
  1474. ;;
  1475. *)
  1476. __docker_complete_containers_running
  1477. ;;
  1478. esac
  1479. }
  1480. _docker_container_stop() {
  1481. case "$prev" in
  1482. --time|-t)
  1483. return
  1484. ;;
  1485. esac
  1486. case "$cur" in
  1487. -*)
  1488. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1489. ;;
  1490. *)
  1491. __docker_complete_containers_running
  1492. ;;
  1493. esac
  1494. }
  1495. _docker_container_top() {
  1496. case "$cur" in
  1497. -*)
  1498. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1499. ;;
  1500. *)
  1501. local counter=$(__docker_pos_first_nonflag)
  1502. if [ $cword -eq $counter ]; then
  1503. __docker_complete_containers_running
  1504. fi
  1505. ;;
  1506. esac
  1507. }
  1508. _docker_container_unpause() {
  1509. case "$cur" in
  1510. -*)
  1511. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1512. ;;
  1513. *)
  1514. local counter=$(__docker_pos_first_nonflag)
  1515. if [ $cword -eq $counter ]; then
  1516. __docker_complete_containers_unpauseable
  1517. fi
  1518. ;;
  1519. esac
  1520. }
  1521. _docker_container_update() {
  1522. local options_with_args="
  1523. --blkio-weight
  1524. --cpu-period
  1525. --cpu-quota
  1526. --cpu-rt-period
  1527. --cpu-rt-runtime
  1528. --cpuset-cpus
  1529. --cpuset-mems
  1530. --cpu-shares -c
  1531. --kernel-memory
  1532. --memory -m
  1533. --memory-reservation
  1534. --memory-swap
  1535. --restart
  1536. "
  1537. local boolean_options="
  1538. --help
  1539. "
  1540. local all_options="$options_with_args $boolean_options"
  1541. __docker_complete_restart && return
  1542. case "$prev" in
  1543. $(__docker_to_extglob "$options_with_args") )
  1544. return
  1545. ;;
  1546. esac
  1547. case "$cur" in
  1548. -*)
  1549. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1550. ;;
  1551. *)
  1552. __docker_complete_containers_all
  1553. ;;
  1554. esac
  1555. }
  1556. _docker_container_wait() {
  1557. case "$cur" in
  1558. -*)
  1559. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1560. ;;
  1561. *)
  1562. __docker_complete_containers_all
  1563. ;;
  1564. esac
  1565. }
  1566. _docker_commit() {
  1567. _docker_container_commit
  1568. }
  1569. _docker_cp() {
  1570. _docker_container_cp
  1571. }
  1572. _docker_create() {
  1573. _docker_container_run
  1574. }
  1575. _docker_daemon() {
  1576. local boolean_options="
  1577. $global_boolean_options
  1578. --disable-legacy-registry
  1579. --experimental
  1580. --help
  1581. --icc=false
  1582. --init
  1583. --ip-forward=false
  1584. --ip-masq=false
  1585. --iptables=false
  1586. --ipv6
  1587. --live-restore
  1588. --raw-logs
  1589. --selinux-enabled
  1590. --userland-proxy=false
  1591. "
  1592. local options_with_args="
  1593. $global_options_with_args
  1594. --add-runtime
  1595. --api-cors-header
  1596. --authorization-plugin
  1597. --bip
  1598. --bridge -b
  1599. --cgroup-parent
  1600. --cluster-advertise
  1601. --cluster-store
  1602. --cluster-store-opt
  1603. --config-file
  1604. --containerd
  1605. --default-gateway
  1606. --default-gateway-v6
  1607. --default-ulimit
  1608. --dns
  1609. --dns-search
  1610. --dns-opt
  1611. --exec-opt
  1612. --exec-root
  1613. --fixed-cidr
  1614. --fixed-cidr-v6
  1615. --graph -g
  1616. --group -G
  1617. --init-path
  1618. --insecure-registry
  1619. --ip
  1620. --label
  1621. --log-driver
  1622. --log-opt
  1623. --max-concurrent-downloads
  1624. --max-concurrent-uploads
  1625. --mtu
  1626. --oom-score-adjust
  1627. --pidfile -p
  1628. --registry-mirror
  1629. --seccomp-profile
  1630. --shutdown-timeout
  1631. --storage-driver -s
  1632. --storage-opt
  1633. --userland-proxy-path
  1634. --userns-remap
  1635. "
  1636. __docker_complete_log_driver_options && return
  1637. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  1638. case "$key" in
  1639. kv.*file)
  1640. cur=${cur##*=}
  1641. _filedir
  1642. return
  1643. ;;
  1644. esac
  1645. local key=$(__docker_map_key_of_current_option '--storage-opt')
  1646. case "$key" in
  1647. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  1648. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1649. return
  1650. ;;
  1651. dm.fs)
  1652. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  1653. return
  1654. ;;
  1655. dm.thinpooldev)
  1656. cur=${cur##*=}
  1657. _filedir
  1658. return
  1659. ;;
  1660. esac
  1661. case "$prev" in
  1662. --authorization-plugin)
  1663. __docker_complete_plugins_bundled --type Authorization
  1664. return
  1665. ;;
  1666. --cluster-store)
  1667. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  1668. __docker_nospace
  1669. return
  1670. ;;
  1671. --cluster-store-opt)
  1672. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  1673. __docker_nospace
  1674. return
  1675. ;;
  1676. --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey|--userland-proxy-path)
  1677. _filedir
  1678. return
  1679. ;;
  1680. --exec-root|--graph|-g)
  1681. _filedir -d
  1682. return
  1683. ;;
  1684. --log-driver)
  1685. __docker_complete_log_drivers
  1686. return
  1687. ;;
  1688. --storage-driver|-s)
  1689. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  1690. return
  1691. ;;
  1692. --storage-opt)
  1693. local btrfs_options="btrfs.min_space"
  1694. local devicemapper_options="
  1695. dm.basesize
  1696. dm.blkdiscard
  1697. dm.blocksize
  1698. dm.fs
  1699. dm.loopdatasize
  1700. dm.loopmetadatasize
  1701. dm.min_free_space
  1702. dm.mkfsarg
  1703. dm.mountopt
  1704. dm.override_udev_sync_check
  1705. dm.thinpooldev
  1706. dm.use_deferred_deletion
  1707. dm.use_deferred_removal
  1708. "
  1709. local zfs_options="zfs.fsname"
  1710. case $(__docker_value_of_option '--storage-driver|-s') in
  1711. '')
  1712. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  1713. ;;
  1714. btrfs)
  1715. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  1716. ;;
  1717. devicemapper)
  1718. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  1719. ;;
  1720. zfs)
  1721. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  1722. ;;
  1723. *)
  1724. return
  1725. ;;
  1726. esac
  1727. __docker_nospace
  1728. return
  1729. ;;
  1730. --log-level|-l)
  1731. __docker_complete_log_levels
  1732. return
  1733. ;;
  1734. --log-opt)
  1735. __docker_complete_log_options
  1736. return
  1737. ;;
  1738. --seccomp-profile)
  1739. _filedir json
  1740. return
  1741. ;;
  1742. --userns-remap)
  1743. __docker_complete_user_group
  1744. return
  1745. ;;
  1746. $(__docker_to_extglob "$options_with_args") )
  1747. return
  1748. ;;
  1749. esac
  1750. case "$cur" in
  1751. -*)
  1752. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1753. ;;
  1754. esac
  1755. }
  1756. _docker_deploy() {
  1757. __docker_is_experimental && _docker_stack_deploy
  1758. }
  1759. _docker_diff() {
  1760. _docker_container_diff
  1761. }
  1762. _docker_events() {
  1763. _docker_system_events
  1764. }
  1765. _docker_exec() {
  1766. _docker_container_exec
  1767. }
  1768. _docker_export() {
  1769. _docker_container_export
  1770. }
  1771. _docker_help() {
  1772. local counter=$(__docker_pos_first_nonflag)
  1773. if [ $cword -eq $counter ]; then
  1774. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1775. fi
  1776. }
  1777. _docker_history() {
  1778. _docker_image_history
  1779. }
  1780. _docker_image() {
  1781. local subcommands="
  1782. build
  1783. history
  1784. import
  1785. inspect
  1786. load
  1787. ls
  1788. prune
  1789. pull
  1790. push
  1791. rm
  1792. save
  1793. tag
  1794. "
  1795. local aliases="
  1796. images
  1797. list
  1798. remove
  1799. rmi
  1800. "
  1801. __docker_subcommands "$subcommands $aliases" && return
  1802. case "$cur" in
  1803. -*)
  1804. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1805. ;;
  1806. *)
  1807. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1808. ;;
  1809. esac
  1810. }
  1811. _docker_image_build() {
  1812. local options_with_args="
  1813. --build-arg
  1814. --cache-from
  1815. --cgroup-parent
  1816. --cpuset-cpus
  1817. --cpuset-mems
  1818. --cpu-shares -c
  1819. --cpu-period
  1820. --cpu-quota
  1821. --file -f
  1822. --isolation
  1823. --label
  1824. --memory -m
  1825. --memory-swap
  1826. --network
  1827. --shm-size
  1828. --tag -t
  1829. --ulimit
  1830. "
  1831. local boolean_options="
  1832. --compress
  1833. --disable-content-trust=false
  1834. --force-rm
  1835. --help
  1836. --no-cache
  1837. --pull
  1838. --quiet -q
  1839. --rm
  1840. "
  1841. local all_options="$options_with_args $boolean_options"
  1842. case "$prev" in
  1843. --build-arg)
  1844. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1845. __docker_nospace
  1846. return
  1847. ;;
  1848. --cache-from)
  1849. __docker_complete_image_repos_and_tags
  1850. return
  1851. ;;
  1852. --file|-f)
  1853. _filedir
  1854. return
  1855. ;;
  1856. --isolation)
  1857. __docker_complete_isolation
  1858. return
  1859. ;;
  1860. --network)
  1861. case "$cur" in
  1862. container:*)
  1863. __docker_complete_containers_all --cur "${cur#*:}"
  1864. ;;
  1865. *)
  1866. COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") )
  1867. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1868. __docker_nospace
  1869. fi
  1870. ;;
  1871. esac
  1872. return
  1873. ;;
  1874. --tag|-t)
  1875. __docker_complete_image_repos_and_tags
  1876. return
  1877. ;;
  1878. $(__docker_to_extglob "$options_with_args") )
  1879. return
  1880. ;;
  1881. esac
  1882. case "$cur" in
  1883. -*)
  1884. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1885. ;;
  1886. *)
  1887. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1888. if [ $cword -eq $counter ]; then
  1889. _filedir -d
  1890. fi
  1891. ;;
  1892. esac
  1893. }
  1894. _docker_image_history() {
  1895. case "$cur" in
  1896. -*)
  1897. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1898. ;;
  1899. *)
  1900. local counter=$(__docker_pos_first_nonflag)
  1901. if [ $cword -eq $counter ]; then
  1902. __docker_complete_images
  1903. fi
  1904. ;;
  1905. esac
  1906. }
  1907. _docker_image_images() {
  1908. _docker_image_ls
  1909. }
  1910. _docker_image_import() {
  1911. case "$prev" in
  1912. --change|-c|--message|-m)
  1913. return
  1914. ;;
  1915. esac
  1916. case "$cur" in
  1917. -*)
  1918. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1919. ;;
  1920. *)
  1921. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1922. if [ $cword -eq $counter ]; then
  1923. return
  1924. fi
  1925. (( counter++ ))
  1926. if [ $cword -eq $counter ]; then
  1927. __docker_complete_image_repos_and_tags
  1928. return
  1929. fi
  1930. ;;
  1931. esac
  1932. }
  1933. _docker_image_inspect() {
  1934. _docker_inspect --type image
  1935. }
  1936. _docker_image_load() {
  1937. case "$prev" in
  1938. --input|-i)
  1939. _filedir
  1940. return
  1941. ;;
  1942. esac
  1943. case "$cur" in
  1944. -*)
  1945. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1946. ;;
  1947. esac
  1948. }
  1949. _docker_image_list() {
  1950. _docker_image_ls
  1951. }
  1952. _docker_image_ls() {
  1953. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1954. case "$key" in
  1955. before|since|reference)
  1956. cur="${cur##*=}"
  1957. __docker_complete_images
  1958. return
  1959. ;;
  1960. dangling)
  1961. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1962. return
  1963. ;;
  1964. label)
  1965. return
  1966. ;;
  1967. esac
  1968. case "$prev" in
  1969. --filter|-f)
  1970. COMPREPLY=( $( compgen -S = -W "before dangling label reference since" -- "$cur" ) )
  1971. __docker_nospace
  1972. return
  1973. ;;
  1974. --format)
  1975. return
  1976. ;;
  1977. esac
  1978. case "$cur" in
  1979. -*)
  1980. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1981. ;;
  1982. =)
  1983. return
  1984. ;;
  1985. *)
  1986. __docker_complete_image_repos
  1987. ;;
  1988. esac
  1989. }
  1990. _docker_image_prune() {
  1991. case "$cur" in
  1992. -*)
  1993. COMPREPLY=( $( compgen -W "--all -a --force -f --help" -- "$cur" ) )
  1994. ;;
  1995. esac
  1996. }
  1997. _docker_image_pull() {
  1998. case "$cur" in
  1999. -*)
  2000. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2001. ;;
  2002. *)
  2003. local counter=$(__docker_pos_first_nonflag)
  2004. if [ $cword -eq $counter ]; then
  2005. for arg in "${COMP_WORDS[@]}"; do
  2006. case "$arg" in
  2007. --all-tags|-a)
  2008. __docker_complete_image_repos
  2009. return
  2010. ;;
  2011. esac
  2012. done
  2013. __docker_complete_image_repos_and_tags
  2014. fi
  2015. ;;
  2016. esac
  2017. }
  2018. _docker_image_push() {
  2019. case "$cur" in
  2020. -*)
  2021. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2022. ;;
  2023. *)
  2024. local counter=$(__docker_pos_first_nonflag)
  2025. if [ $cword -eq $counter ]; then
  2026. __docker_complete_image_repos_and_tags
  2027. fi
  2028. ;;
  2029. esac
  2030. }
  2031. _docker_image_remove() {
  2032. _docker_image_rm
  2033. }
  2034. _docker_image_rm() {
  2035. case "$cur" in
  2036. -*)
  2037. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2038. ;;
  2039. *)
  2040. __docker_complete_images
  2041. ;;
  2042. esac
  2043. }
  2044. _docker_image_rmi() {
  2045. _docker_image_rm
  2046. }
  2047. _docker_image_save() {
  2048. case "$prev" in
  2049. --output|-o)
  2050. _filedir
  2051. return
  2052. ;;
  2053. esac
  2054. case "$cur" in
  2055. -*)
  2056. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2057. ;;
  2058. *)
  2059. __docker_complete_images
  2060. ;;
  2061. esac
  2062. }
  2063. _docker_image_tag() {
  2064. case "$cur" in
  2065. -*)
  2066. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2067. ;;
  2068. *)
  2069. local counter=$(__docker_pos_first_nonflag)
  2070. if [ $cword -eq $counter ]; then
  2071. __docker_complete_image_repos_and_tags
  2072. return
  2073. fi
  2074. (( counter++ ))
  2075. if [ $cword -eq $counter ]; then
  2076. __docker_complete_image_repos_and_tags
  2077. return
  2078. fi
  2079. ;;
  2080. esac
  2081. }
  2082. _docker_images() {
  2083. _docker_image_ls
  2084. }
  2085. _docker_import() {
  2086. _docker_image_import
  2087. }
  2088. _docker_info() {
  2089. _docker_system_info
  2090. }
  2091. _docker_inspect() {
  2092. local preselected_type
  2093. local type
  2094. if [ "$1" = "--type" ] ; then
  2095. preselected_type=yes
  2096. type="$2"
  2097. else
  2098. type=$(__docker_value_of_option --type)
  2099. fi
  2100. case "$prev" in
  2101. --format|-f)
  2102. return
  2103. ;;
  2104. --type)
  2105. if [ -z "$preselected_type" ] ; then
  2106. COMPREPLY=( $( compgen -W "container image network node plugin service volume" -- "$cur" ) )
  2107. return
  2108. fi
  2109. ;;
  2110. esac
  2111. case "$cur" in
  2112. -*)
  2113. local options="--format -f --help --size -s"
  2114. if [ -z "$preselected_type" ] ; then
  2115. options+=" --type"
  2116. fi
  2117. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  2118. ;;
  2119. *)
  2120. case "$type" in
  2121. '')
  2122. COMPREPLY=( $( compgen -W "
  2123. $(__docker_containers --all)
  2124. $(__docker_images)
  2125. $(__docker_networks)
  2126. $(__docker_nodes)
  2127. $(__docker_plugins_installed)
  2128. $(__docker_services)
  2129. $(__docker_volumes)
  2130. " -- "$cur" ) )
  2131. ;;
  2132. container)
  2133. __docker_complete_containers_all
  2134. ;;
  2135. image)
  2136. __docker_complete_images
  2137. ;;
  2138. network)
  2139. __docker_complete_networks
  2140. ;;
  2141. node)
  2142. __docker_complete_nodes
  2143. ;;
  2144. plugin)
  2145. __docker_complete_plugins_installed
  2146. ;;
  2147. service)
  2148. __docker_complete_services
  2149. ;;
  2150. volume)
  2151. __docker_complete_volumes
  2152. ;;
  2153. esac
  2154. esac
  2155. }
  2156. _docker_kill() {
  2157. _docker_container_kill
  2158. }
  2159. _docker_load() {
  2160. _docker_image_load
  2161. }
  2162. _docker_login() {
  2163. case "$prev" in
  2164. --password|-p|--username|-u)
  2165. return
  2166. ;;
  2167. esac
  2168. case "$cur" in
  2169. -*)
  2170. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  2171. ;;
  2172. esac
  2173. }
  2174. _docker_logout() {
  2175. case "$cur" in
  2176. -*)
  2177. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2178. ;;
  2179. esac
  2180. }
  2181. _docker_logs() {
  2182. _docker_container_logs
  2183. }
  2184. _docker_network_connect() {
  2185. local options_with_args="
  2186. --alias
  2187. --ip
  2188. --ip6
  2189. --link
  2190. --link-local-ip
  2191. "
  2192. local boolean_options="
  2193. --help
  2194. "
  2195. case "$prev" in
  2196. --link)
  2197. case "$cur" in
  2198. *:*)
  2199. ;;
  2200. *)
  2201. __docker_complete_containers_running
  2202. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2203. __docker_nospace
  2204. ;;
  2205. esac
  2206. return
  2207. ;;
  2208. $(__docker_to_extglob "$options_with_args") )
  2209. return
  2210. ;;
  2211. esac
  2212. case "$cur" in
  2213. -*)
  2214. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2215. ;;
  2216. *)
  2217. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2218. if [ $cword -eq $counter ]; then
  2219. __docker_complete_networks
  2220. elif [ $cword -eq $(($counter + 1)) ]; then
  2221. __docker_complete_containers_all
  2222. fi
  2223. ;;
  2224. esac
  2225. }
  2226. _docker_network_create() {
  2227. case "$prev" in
  2228. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  2229. return
  2230. ;;
  2231. --ipam-driver)
  2232. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  2233. return
  2234. ;;
  2235. --driver|-d)
  2236. # remove drivers that allow one instance only, add drivers missing in `docker info`
  2237. __docker_complete_plugins_bundled --type Network --remove host --remove null --add macvlan
  2238. return
  2239. ;;
  2240. --label)
  2241. return
  2242. ;;
  2243. esac
  2244. case "$cur" in
  2245. -*)
  2246. COMPREPLY=( $( compgen -W "--attachable --aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  2247. ;;
  2248. esac
  2249. }
  2250. _docker_network_disconnect() {
  2251. case "$cur" in
  2252. -*)
  2253. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2254. ;;
  2255. *)
  2256. local counter=$(__docker_pos_first_nonflag)
  2257. if [ $cword -eq $counter ]; then
  2258. __docker_complete_networks
  2259. elif [ $cword -eq $(($counter + 1)) ]; then
  2260. __docker_complete_containers_in_network "$prev"
  2261. fi
  2262. ;;
  2263. esac
  2264. }
  2265. _docker_network_inspect() {
  2266. case "$prev" in
  2267. --format|-f)
  2268. return
  2269. ;;
  2270. esac
  2271. case "$cur" in
  2272. -*)
  2273. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2274. ;;
  2275. *)
  2276. __docker_complete_networks
  2277. esac
  2278. }
  2279. _docker_network_ls() {
  2280. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2281. case "$key" in
  2282. driver)
  2283. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Network --add macvlan
  2284. return
  2285. ;;
  2286. id)
  2287. __docker_complete_networks --cur "${cur##*=}" --id
  2288. return
  2289. ;;
  2290. name)
  2291. __docker_complete_networks --cur "${cur##*=}" --name
  2292. return
  2293. ;;
  2294. type)
  2295. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  2296. return
  2297. ;;
  2298. esac
  2299. case "$prev" in
  2300. --filter|-f)
  2301. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  2302. __docker_nospace
  2303. return
  2304. ;;
  2305. --format)
  2306. return
  2307. ;;
  2308. esac
  2309. case "$cur" in
  2310. -*)
  2311. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  2312. ;;
  2313. esac
  2314. }
  2315. _docker_network_prune() {
  2316. case "$cur" in
  2317. -*)
  2318. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2319. ;;
  2320. esac
  2321. }
  2322. _docker_network_rm() {
  2323. case "$cur" in
  2324. -*)
  2325. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2326. ;;
  2327. *)
  2328. __docker_complete_networks --filter type=custom
  2329. esac
  2330. }
  2331. _docker_network() {
  2332. local subcommands="
  2333. connect
  2334. create
  2335. disconnect
  2336. inspect
  2337. ls
  2338. prune
  2339. rm
  2340. "
  2341. __docker_subcommands "$subcommands" && return
  2342. case "$cur" in
  2343. -*)
  2344. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2345. ;;
  2346. *)
  2347. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2348. ;;
  2349. esac
  2350. }
  2351. _docker_service() {
  2352. local subcommands="
  2353. create
  2354. inspect
  2355. ls list
  2356. rm remove
  2357. scale
  2358. ps
  2359. update
  2360. "
  2361. __docker_subcommands "$subcommands" && return
  2362. case "$cur" in
  2363. -*)
  2364. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2365. ;;
  2366. *)
  2367. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2368. ;;
  2369. esac
  2370. }
  2371. _docker_service_create() {
  2372. _docker_service_update
  2373. }
  2374. _docker_service_inspect() {
  2375. case "$prev" in
  2376. --format|-f)
  2377. return
  2378. ;;
  2379. esac
  2380. case "$cur" in
  2381. -*)
  2382. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2383. ;;
  2384. *)
  2385. __docker_complete_services
  2386. esac
  2387. }
  2388. _docker_service_list() {
  2389. _docker_service_ls
  2390. }
  2391. _docker_service_ls() {
  2392. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2393. case "$key" in
  2394. id)
  2395. __docker_complete_services --cur "${cur##*=}" --id
  2396. return
  2397. ;;
  2398. name)
  2399. __docker_complete_services --cur "${cur##*=}" --name
  2400. return
  2401. ;;
  2402. esac
  2403. case "$prev" in
  2404. --filter|-f)
  2405. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2406. __docker_nospace
  2407. return
  2408. ;;
  2409. esac
  2410. case "$cur" in
  2411. -*)
  2412. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2413. ;;
  2414. esac
  2415. }
  2416. _docker_service_remove() {
  2417. _docker_service_rm
  2418. }
  2419. _docker_service_rm() {
  2420. case "$cur" in
  2421. -*)
  2422. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2423. ;;
  2424. *)
  2425. __docker_complete_services
  2426. esac
  2427. }
  2428. _docker_service_scale() {
  2429. case "$cur" in
  2430. -*)
  2431. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2432. ;;
  2433. *)
  2434. __docker_complete_services
  2435. __docker_append_to_completions "="
  2436. __docker_nospace
  2437. ;;
  2438. esac
  2439. }
  2440. _docker_service_ps() {
  2441. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2442. case "$key" in
  2443. desired-state)
  2444. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2445. return
  2446. ;;
  2447. name)
  2448. __docker_complete_services --cur "${cur##*=}" --name
  2449. return
  2450. ;;
  2451. esac
  2452. case "$prev" in
  2453. --filter|-f)
  2454. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  2455. __docker_nospace
  2456. return
  2457. ;;
  2458. esac
  2459. case "$cur" in
  2460. -*)
  2461. COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) )
  2462. ;;
  2463. *)
  2464. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  2465. if [ $cword -eq $counter ]; then
  2466. __docker_complete_services
  2467. fi
  2468. ;;
  2469. esac
  2470. }
  2471. _docker_service_update() {
  2472. local $subcommand="${words[$subcommand_pos]}"
  2473. local options_with_args="
  2474. --constraint
  2475. --endpoint-mode
  2476. --env -e
  2477. --force
  2478. --health-cmd
  2479. --health-interval
  2480. --health-retries
  2481. --health-timeout
  2482. --hostname
  2483. --label -l
  2484. --limit-cpu
  2485. --limit-memory
  2486. --log-driver
  2487. --log-opt
  2488. --mount
  2489. --network
  2490. --no-healthcheck
  2491. --publish -p
  2492. --replicas
  2493. --reserve-cpu
  2494. --reserve-memory
  2495. --restart-condition
  2496. --restart-delay
  2497. --restart-max-attempts
  2498. --restart-window
  2499. --rollback
  2500. --stop-grace-period
  2501. --update-delay
  2502. --update-failure-action
  2503. --update-max-failure-ratio
  2504. --update-monitor
  2505. --update-parallelism
  2506. --user -u
  2507. --workdir -w
  2508. "
  2509. local boolean_options="
  2510. --help
  2511. --tty -t
  2512. --with-registry-auth
  2513. "
  2514. __docker_complete_log_driver_options && return
  2515. if [ "$subcommand" = "create" ] ; then
  2516. options_with_args="$options_with_args
  2517. --container-label
  2518. --dns
  2519. --dns-option
  2520. --dns-search
  2521. --env-file
  2522. --group
  2523. --host
  2524. --mode
  2525. --name
  2526. --publish
  2527. --secret
  2528. "
  2529. case "$prev" in
  2530. --env-file)
  2531. _filedir
  2532. return
  2533. ;;
  2534. --host)
  2535. case "$cur" in
  2536. *:)
  2537. __docker_complete_resolved_hostname
  2538. return
  2539. ;;
  2540. esac
  2541. ;;
  2542. --mode)
  2543. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  2544. return
  2545. ;;
  2546. --secret)
  2547. __docker_complete_secrets
  2548. return
  2549. ;;
  2550. --group)
  2551. COMPREPLY=( $(compgen -g -- "$cur") )
  2552. return
  2553. ;;
  2554. esac
  2555. fi
  2556. if [ "$subcommand" = "update" ] ; then
  2557. options_with_args="$options_with_args
  2558. --arg
  2559. --container-label-add
  2560. --container-label-rm
  2561. --dns-add
  2562. --dns-option-add
  2563. --dns-option-rm
  2564. --dns-rm
  2565. --dns-search-add
  2566. --dns-search-rm
  2567. --group-add
  2568. --group-rm
  2569. --host-add
  2570. --host-rm
  2571. --image
  2572. --publish-add
  2573. --publish-rm
  2574. --secret-add
  2575. --secret-rm
  2576. "
  2577. case "$prev" in
  2578. --group-add)
  2579. COMPREPLY=( $(compgen -g -- "$cur") )
  2580. return
  2581. ;;
  2582. --group-rm)
  2583. COMPREPLY=( $(compgen -g -- "$cur") )
  2584. return
  2585. ;;
  2586. --host-add|--host-rm)
  2587. case "$cur" in
  2588. *:)
  2589. __docker_complete_resolved_hostname
  2590. return
  2591. ;;
  2592. esac
  2593. ;;
  2594. --image)
  2595. __docker_complete_image_repos_and_tags
  2596. return
  2597. ;;
  2598. --secret-add|--secret-rm)
  2599. __docker_complete_secrets
  2600. return
  2601. ;;
  2602. esac
  2603. fi
  2604. case "$prev" in
  2605. --endpoint-mode)
  2606. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  2607. return
  2608. ;;
  2609. --env|-e)
  2610. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2611. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2612. __docker_nospace
  2613. return
  2614. ;;
  2615. --log-driver)
  2616. __docker_complete_log_drivers
  2617. return
  2618. ;;
  2619. --log-opt)
  2620. __docker_complete_log_options
  2621. return
  2622. ;;
  2623. --network)
  2624. __docker_complete_networks
  2625. return
  2626. ;;
  2627. --restart-condition)
  2628. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  2629. return
  2630. ;;
  2631. --user|-u)
  2632. __docker_complete_user_group
  2633. return
  2634. ;;
  2635. $(__docker_to_extglob "$options_with_args") )
  2636. return
  2637. ;;
  2638. esac
  2639. case "$cur" in
  2640. -*)
  2641. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2642. ;;
  2643. *)
  2644. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2645. if [ "$subcommand" = "update" ] ; then
  2646. if [ $cword -eq $counter ]; then
  2647. __docker_complete_services
  2648. fi
  2649. else
  2650. if [ $cword -eq $counter ]; then
  2651. __docker_complete_images
  2652. fi
  2653. fi
  2654. ;;
  2655. esac
  2656. }
  2657. _docker_swarm() {
  2658. local subcommands="
  2659. init
  2660. join
  2661. join-token
  2662. leave
  2663. update
  2664. "
  2665. __docker_subcommands "$subcommands" && return
  2666. case "$cur" in
  2667. -*)
  2668. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2669. ;;
  2670. *)
  2671. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2672. ;;
  2673. esac
  2674. }
  2675. _docker_swarm_init() {
  2676. case "$prev" in
  2677. --advertise-addr)
  2678. if [[ $cur == *: ]] ; then
  2679. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2680. else
  2681. __docker_complete_local_interfaces
  2682. __docker_nospace
  2683. fi
  2684. return
  2685. ;;
  2686. --listen-addr)
  2687. if [[ $cur == *: ]] ; then
  2688. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2689. else
  2690. __docker_complete_local_interfaces --add 0.0.0.0
  2691. __docker_nospace
  2692. fi
  2693. return
  2694. ;;
  2695. esac
  2696. case "$cur" in
  2697. -*)
  2698. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  2699. ;;
  2700. esac
  2701. }
  2702. _docker_swarm_join() {
  2703. case "$prev" in
  2704. --advertise-addr)
  2705. if [[ $cur == *: ]] ; then
  2706. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2707. else
  2708. __docker_complete_local_interfaces
  2709. __docker_nospace
  2710. fi
  2711. return
  2712. ;;
  2713. --listen-addr)
  2714. if [[ $cur == *: ]] ; then
  2715. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2716. else
  2717. __docker_complete_local_interfaces --add 0.0.0.0
  2718. __docker_nospace
  2719. fi
  2720. return
  2721. ;;
  2722. --token)
  2723. return
  2724. ;;
  2725. esac
  2726. case "$cur" in
  2727. -*)
  2728. COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) )
  2729. ;;
  2730. *:)
  2731. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2732. ;;
  2733. esac
  2734. }
  2735. _docker_swarm_join-token() {
  2736. case "$cur" in
  2737. -*)
  2738. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  2739. ;;
  2740. *)
  2741. local counter=$( __docker_pos_first_nonflag )
  2742. if [ $cword -eq $counter ]; then
  2743. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2744. fi
  2745. ;;
  2746. esac
  2747. }
  2748. _docker_swarm_leave() {
  2749. case "$cur" in
  2750. -*)
  2751. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2752. ;;
  2753. esac
  2754. }
  2755. _docker_swarm_update() {
  2756. case "$prev" in
  2757. --cert-expiry|--dispatcher-heartbeat|--max-snapshots|--snapshot-interval|--task-history-limit)
  2758. return
  2759. ;;
  2760. esac
  2761. case "$cur" in
  2762. -*)
  2763. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
  2764. ;;
  2765. esac
  2766. }
  2767. _docker_node() {
  2768. local subcommands="
  2769. demote
  2770. inspect
  2771. ls list
  2772. promote
  2773. rm remove
  2774. ps
  2775. update
  2776. "
  2777. __docker_subcommands "$subcommands" && return
  2778. case "$cur" in
  2779. -*)
  2780. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2781. ;;
  2782. *)
  2783. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2784. ;;
  2785. esac
  2786. }
  2787. _docker_node_demote() {
  2788. case "$cur" in
  2789. -*)
  2790. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2791. ;;
  2792. *)
  2793. __docker_complete_nodes --filter role=manager
  2794. esac
  2795. }
  2796. _docker_node_inspect() {
  2797. case "$prev" in
  2798. --format|-f)
  2799. return
  2800. ;;
  2801. esac
  2802. case "$cur" in
  2803. -*)
  2804. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2805. ;;
  2806. *)
  2807. __docker_complete_nodes_plus_self
  2808. esac
  2809. }
  2810. _docker_node_list() {
  2811. _docker_node_ls
  2812. }
  2813. _docker_node_ls() {
  2814. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2815. case "$key" in
  2816. id)
  2817. __docker_complete_nodes --cur "${cur##*=}" --id
  2818. return
  2819. ;;
  2820. name)
  2821. __docker_complete_nodes --cur "${cur##*=}" --name
  2822. return
  2823. ;;
  2824. esac
  2825. case "$prev" in
  2826. --filter|-f)
  2827. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2828. __docker_nospace
  2829. return
  2830. ;;
  2831. esac
  2832. case "$cur" in
  2833. -*)
  2834. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2835. ;;
  2836. esac
  2837. }
  2838. _docker_node_promote() {
  2839. case "$cur" in
  2840. -*)
  2841. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2842. ;;
  2843. *)
  2844. __docker_complete_nodes --filter role=worker
  2845. esac
  2846. }
  2847. _docker_node_remove() {
  2848. _docker_node_rm
  2849. }
  2850. _docker_node_rm() {
  2851. case "$cur" in
  2852. -*)
  2853. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2854. ;;
  2855. *)
  2856. __docker_complete_nodes
  2857. esac
  2858. }
  2859. _docker_node_ps() {
  2860. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2861. case "$key" in
  2862. desired-state)
  2863. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2864. return
  2865. ;;
  2866. name)
  2867. __docker_complete_services --cur "${cur##*=}" --name
  2868. return
  2869. ;;
  2870. esac
  2871. case "$prev" in
  2872. --filter|-f)
  2873. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  2874. __docker_nospace
  2875. return
  2876. ;;
  2877. esac
  2878. case "$cur" in
  2879. -*)
  2880. COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  2881. ;;
  2882. *)
  2883. __docker_complete_nodes_plus_self
  2884. ;;
  2885. esac
  2886. }
  2887. _docker_node_update() {
  2888. case "$prev" in
  2889. --availability)
  2890. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2891. return
  2892. ;;
  2893. --role)
  2894. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2895. return
  2896. ;;
  2897. --label-add|--label-rm)
  2898. return
  2899. ;;
  2900. esac
  2901. case "$cur" in
  2902. -*)
  2903. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  2904. ;;
  2905. *)
  2906. __docker_complete_nodes
  2907. esac
  2908. }
  2909. _docker_pause() {
  2910. _docker_container_pause
  2911. }
  2912. _docker_plugin() {
  2913. local subcommands="
  2914. create
  2915. disable
  2916. enable
  2917. inspect
  2918. install
  2919. ls
  2920. push
  2921. rm
  2922. set
  2923. "
  2924. local aliases="
  2925. list
  2926. remove
  2927. "
  2928. __docker_subcommands "$subcommands $aliases" && return
  2929. case "$cur" in
  2930. -*)
  2931. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2932. ;;
  2933. *)
  2934. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2935. ;;
  2936. esac
  2937. }
  2938. _docker_plugin_create() {
  2939. case "$cur" in
  2940. -*)
  2941. COMPREPLY=( $( compgen -W "--compress --help" -- "$cur" ) )
  2942. ;;
  2943. *)
  2944. local counter=$(__docker_pos_first_nonflag)
  2945. if [ $cword -eq $counter ]; then
  2946. # reponame
  2947. return
  2948. elif [ $cword -eq $((counter + 1)) ]; then
  2949. _filedir -d
  2950. fi
  2951. ;;
  2952. esac
  2953. }
  2954. _docker_plugin_disable() {
  2955. case "$cur" in
  2956. -*)
  2957. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2958. ;;
  2959. *)
  2960. local counter=$(__docker_pos_first_nonflag)
  2961. if [ $cword -eq $counter ]; then
  2962. __docker_complete_plugins_installed
  2963. fi
  2964. ;;
  2965. esac
  2966. }
  2967. _docker_plugin_enable() {
  2968. case "$prev" in
  2969. --timeout)
  2970. return
  2971. ;;
  2972. esac
  2973. case "$cur" in
  2974. -*)
  2975. COMPREPLY=( $( compgen -W "--help --timeout" -- "$cur" ) )
  2976. ;;
  2977. *)
  2978. local counter=$(__docker_pos_first_nonflag '--timeout')
  2979. if [ $cword -eq $counter ]; then
  2980. __docker_complete_plugins_installed
  2981. fi
  2982. ;;
  2983. esac
  2984. }
  2985. _docker_plugin_inspect() {
  2986. case "$prev" in
  2987. --format|f)
  2988. return
  2989. ;;
  2990. esac
  2991. case "$cur" in
  2992. -*)
  2993. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2994. ;;
  2995. *)
  2996. __docker_complete_plugins_installed
  2997. ;;
  2998. esac
  2999. }
  3000. _docker_plugin_install() {
  3001. case "$prev" in
  3002. --alias)
  3003. return
  3004. ;;
  3005. esac
  3006. case "$cur" in
  3007. -*)
  3008. COMPREPLY=( $( compgen -W "--alias --disable --grant-all-permissions --help" -- "$cur" ) )
  3009. ;;
  3010. esac
  3011. }
  3012. _docker_plugin_list() {
  3013. _docker_plugin_ls
  3014. }
  3015. _docker_plugin_ls() {
  3016. case "$cur" in
  3017. -*)
  3018. COMPREPLY=( $( compgen -W "--help --no-trunc" -- "$cur" ) )
  3019. ;;
  3020. esac
  3021. }
  3022. _docker_plugin_push() {
  3023. case "$cur" in
  3024. -*)
  3025. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3026. ;;
  3027. *)
  3028. local counter=$(__docker_pos_first_nonflag)
  3029. if [ $cword -eq $counter ]; then
  3030. __docker_complete_plugins_installed
  3031. fi
  3032. ;;
  3033. esac
  3034. }
  3035. _docker_plugin_remove() {
  3036. _docker_plugin_rm
  3037. }
  3038. _docker_plugin_rm() {
  3039. case "$cur" in
  3040. -*)
  3041. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3042. ;;
  3043. *)
  3044. __docker_complete_plugins_installed
  3045. ;;
  3046. esac
  3047. }
  3048. _docker_plugin_set() {
  3049. case "$cur" in
  3050. -*)
  3051. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3052. ;;
  3053. *)
  3054. local counter=$(__docker_pos_first_nonflag)
  3055. if [ $cword -eq $counter ]; then
  3056. __docker_complete_plugins_installed
  3057. fi
  3058. ;;
  3059. esac
  3060. }
  3061. _docker_port() {
  3062. _docker_container_port
  3063. }
  3064. _docker_ps() {
  3065. _docker_container_ls
  3066. }
  3067. _docker_pull() {
  3068. _docker_image_pull
  3069. }
  3070. _docker_push() {
  3071. _docker_image_push
  3072. }
  3073. _docker_rename() {
  3074. _docker_container_rename
  3075. }
  3076. _docker_restart() {
  3077. _docker_container_restart
  3078. }
  3079. _docker_rm() {
  3080. _docker_container_rm
  3081. }
  3082. _docker_rmi() {
  3083. _docker_image_rm
  3084. }
  3085. _docker_run() {
  3086. _docker_container_run
  3087. }
  3088. _docker_save() {
  3089. _docker_image_save
  3090. }
  3091. _docker_secret() {
  3092. local subcommands="
  3093. create
  3094. inspect
  3095. ls
  3096. rm
  3097. "
  3098. local aliases="
  3099. list
  3100. remove
  3101. "
  3102. __docker_subcommands "$subcommands $aliases" && return
  3103. case "$cur" in
  3104. -*)
  3105. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3106. ;;
  3107. *)
  3108. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3109. ;;
  3110. esac
  3111. }
  3112. _docker_secret_create() {
  3113. case "$prev" in
  3114. --label|-l)
  3115. return
  3116. ;;
  3117. esac
  3118. case "$cur" in
  3119. -*)
  3120. COMPREPLY=( $( compgen -W "--help --label -l" -- "$cur" ) )
  3121. ;;
  3122. esac
  3123. }
  3124. _docker_secret_inspect() {
  3125. case "$prev" in
  3126. --format|-f)
  3127. return
  3128. ;;
  3129. esac
  3130. case "$cur" in
  3131. -*)
  3132. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3133. ;;
  3134. *)
  3135. __docker_complete_secrets
  3136. ;;
  3137. esac
  3138. }
  3139. _docker_secret_list() {
  3140. _docker_secret_ls
  3141. }
  3142. _docker_secret_ls() {
  3143. case "$cur" in
  3144. -*)
  3145. COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) )
  3146. ;;
  3147. esac
  3148. }
  3149. _docker_secret_remove() {
  3150. case "$cur" in
  3151. -*)
  3152. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3153. ;;
  3154. *)
  3155. __docker_complete_secrets
  3156. ;;
  3157. esac
  3158. }
  3159. _docker_secret_rm() {
  3160. _docker_secret_remove
  3161. }
  3162. _docker_search() {
  3163. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3164. case "$key" in
  3165. is-automated)
  3166. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3167. return
  3168. ;;
  3169. is-official)
  3170. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3171. return
  3172. ;;
  3173. esac
  3174. case "$prev" in
  3175. --filter|-f)
  3176. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  3177. __docker_nospace
  3178. return
  3179. ;;
  3180. --limit)
  3181. return
  3182. ;;
  3183. esac
  3184. case "$cur" in
  3185. -*)
  3186. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  3187. ;;
  3188. esac
  3189. }
  3190. _docker_stack() {
  3191. local subcommands="
  3192. deploy
  3193. ls
  3194. ps
  3195. rm
  3196. services
  3197. "
  3198. local aliases="
  3199. down
  3200. list
  3201. remove
  3202. up
  3203. "
  3204. __docker_subcommands "$subcommands $aliases" && return
  3205. case "$cur" in
  3206. -*)
  3207. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3208. ;;
  3209. *)
  3210. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3211. ;;
  3212. esac
  3213. }
  3214. _docker_stack_deploy() {
  3215. case "$prev" in
  3216. --bundle-file)
  3217. if __docker_is_experimental ; then
  3218. _filedir dab
  3219. return
  3220. fi
  3221. ;;
  3222. --compose-file|-c)
  3223. _filedir yml
  3224. return
  3225. ;;
  3226. esac
  3227. case "$cur" in
  3228. -*)
  3229. local options="--compose-file -c --help --with-registry-auth"
  3230. __docker_is_experimental && options+=" --bundle-file"
  3231. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  3232. ;;
  3233. esac
  3234. }
  3235. _docker_stack_down() {
  3236. _docker_stack_rm
  3237. }
  3238. _docker_stack_list() {
  3239. _docker_stack_ls
  3240. }
  3241. _docker_stack_ls() {
  3242. case "$cur" in
  3243. -*)
  3244. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3245. ;;
  3246. esac
  3247. }
  3248. _docker_stack_ps() {
  3249. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3250. case "$key" in
  3251. desired-state)
  3252. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  3253. return
  3254. ;;
  3255. id)
  3256. __docker_complete_stacks --cur "${cur##*=}" --id
  3257. return
  3258. ;;
  3259. name)
  3260. __docker_complete_stacks --cur "${cur##*=}" --name
  3261. return
  3262. ;;
  3263. esac
  3264. case "$prev" in
  3265. --filter|-f)
  3266. COMPREPLY=( $( compgen -S = -W "id name desired-state" -- "$cur" ) )
  3267. __docker_nospace
  3268. return
  3269. ;;
  3270. esac
  3271. case "$cur" in
  3272. -*)
  3273. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  3274. ;;
  3275. *)
  3276. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  3277. if [ $cword -eq $counter ]; then
  3278. __docker_complete_stacks
  3279. fi
  3280. ;;
  3281. esac
  3282. }
  3283. _docker_stack_remove() {
  3284. _docker_stack_rm
  3285. }
  3286. _docker_stack_rm() {
  3287. case "$cur" in
  3288. -*)
  3289. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3290. ;;
  3291. *)
  3292. local counter=$(__docker_pos_first_nonflag)
  3293. if [ $cword -eq $counter ]; then
  3294. __docker_complete_stacks
  3295. fi
  3296. ;;
  3297. esac
  3298. }
  3299. _docker_stack_services() {
  3300. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3301. case "$key" in
  3302. id)
  3303. __docker_complete_services --cur "${cur##*=}" --id
  3304. return
  3305. ;;
  3306. label)
  3307. return
  3308. ;;
  3309. name)
  3310. __docker_complete_services --cur "${cur##*=}" --name
  3311. return
  3312. ;;
  3313. esac
  3314. case "$prev" in
  3315. --filter|-f)
  3316. COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
  3317. __docker_nospace
  3318. return
  3319. ;;
  3320. esac
  3321. case "$cur" in
  3322. -*)
  3323. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  3324. ;;
  3325. *)
  3326. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  3327. if [ $cword -eq $counter ]; then
  3328. __docker_complete_stacks
  3329. fi
  3330. ;;
  3331. esac
  3332. }
  3333. _docker_stack_up() {
  3334. _docker_stack_deploy
  3335. }
  3336. _docker_start() {
  3337. _docker_container_start
  3338. }
  3339. _docker_stats() {
  3340. _docker_container_stats
  3341. }
  3342. _docker_stop() {
  3343. _docker_container_stop
  3344. }
  3345. _docker_system() {
  3346. local subcommands="
  3347. df
  3348. events
  3349. info
  3350. prune
  3351. "
  3352. __docker_subcommands "$subcommands $aliases" && return
  3353. case "$cur" in
  3354. -*)
  3355. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3356. ;;
  3357. *)
  3358. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3359. ;;
  3360. esac
  3361. }
  3362. _docker_system_df() {
  3363. case "$cur" in
  3364. -*)
  3365. COMPREPLY=( $( compgen -W "--help --verbose -v" -- "$cur" ) )
  3366. ;;
  3367. esac
  3368. }
  3369. _docker_system_events() {
  3370. local key=$(__docker_map_key_of_current_option '-f|--filter')
  3371. case "$key" in
  3372. container)
  3373. __docker_complete_containers_all --cur "${cur##*=}"
  3374. return
  3375. ;;
  3376. daemon)
  3377. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  3378. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  3379. return
  3380. ;;
  3381. event)
  3382. COMPREPLY=( $( compgen -W "
  3383. attach
  3384. commit
  3385. connect
  3386. copy
  3387. create
  3388. delete
  3389. destroy
  3390. detach
  3391. die
  3392. disconnect
  3393. exec_create
  3394. exec_detach
  3395. exec_start
  3396. export
  3397. health_status
  3398. import
  3399. kill
  3400. load
  3401. mount
  3402. oom
  3403. pause
  3404. pull
  3405. push
  3406. reload
  3407. rename
  3408. resize
  3409. restart
  3410. save
  3411. start
  3412. stop
  3413. tag
  3414. top
  3415. unmount
  3416. unpause
  3417. untag
  3418. update
  3419. " -- "${cur##*=}" ) )
  3420. return
  3421. ;;
  3422. image)
  3423. cur="${cur##*=}"
  3424. __docker_complete_images
  3425. return
  3426. ;;
  3427. network)
  3428. __docker_complete_networks --cur "${cur##*=}"
  3429. return
  3430. ;;
  3431. type)
  3432. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  3433. return
  3434. ;;
  3435. volume)
  3436. __docker_complete_volumes --cur "${cur##*=}"
  3437. return
  3438. ;;
  3439. esac
  3440. case "$prev" in
  3441. --filter|-f)
  3442. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  3443. __docker_nospace
  3444. return
  3445. ;;
  3446. --since|--until)
  3447. return
  3448. ;;
  3449. esac
  3450. case "$cur" in
  3451. -*)
  3452. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  3453. ;;
  3454. esac
  3455. }
  3456. _docker_system_info() {
  3457. case "$prev" in
  3458. --format|-f)
  3459. return
  3460. ;;
  3461. esac
  3462. case "$cur" in
  3463. -*)
  3464. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3465. ;;
  3466. esac
  3467. }
  3468. _docker_system_prune() {
  3469. case "$cur" in
  3470. -*)
  3471. COMPREPLY=( $( compgen -W "--all -a --force -f --help" -- "$cur" ) )
  3472. ;;
  3473. esac
  3474. }
  3475. _docker_tag() {
  3476. _docker_image_tag
  3477. }
  3478. _docker_unpause() {
  3479. _docker_container_unpause
  3480. }
  3481. _docker_update() {
  3482. _docker_container_update
  3483. }
  3484. _docker_top() {
  3485. _docker_container_top
  3486. }
  3487. _docker_version() {
  3488. case "$prev" in
  3489. --format|-f)
  3490. return
  3491. ;;
  3492. esac
  3493. case "$cur" in
  3494. -*)
  3495. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3496. ;;
  3497. esac
  3498. }
  3499. _docker_volume_create() {
  3500. case "$prev" in
  3501. --driver|-d)
  3502. __docker_complete_plugins_bundled --type Volume
  3503. return
  3504. ;;
  3505. --label|--opt|-o)
  3506. return
  3507. ;;
  3508. esac
  3509. case "$cur" in
  3510. -*)
  3511. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  3512. ;;
  3513. esac
  3514. }
  3515. _docker_volume_inspect() {
  3516. case "$prev" in
  3517. --format|-f)
  3518. return
  3519. ;;
  3520. esac
  3521. case "$cur" in
  3522. -*)
  3523. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3524. ;;
  3525. *)
  3526. __docker_complete_volumes
  3527. ;;
  3528. esac
  3529. }
  3530. _docker_volume_ls() {
  3531. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3532. case "$key" in
  3533. dangling)
  3534. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  3535. return
  3536. ;;
  3537. driver)
  3538. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Volume
  3539. return
  3540. ;;
  3541. name)
  3542. __docker_complete_volumes --cur "${cur##*=}"
  3543. return
  3544. ;;
  3545. esac
  3546. case "$prev" in
  3547. --filter|-f)
  3548. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  3549. __docker_nospace
  3550. return
  3551. ;;
  3552. --format)
  3553. return
  3554. ;;
  3555. esac
  3556. case "$cur" in
  3557. -*)
  3558. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  3559. ;;
  3560. esac
  3561. }
  3562. _docker_volume_prune() {
  3563. case "$cur" in
  3564. -*)
  3565. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3566. ;;
  3567. esac
  3568. }
  3569. _docker_volume_rm() {
  3570. case "$cur" in
  3571. -*)
  3572. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3573. ;;
  3574. *)
  3575. __docker_complete_volumes
  3576. ;;
  3577. esac
  3578. }
  3579. _docker_volume() {
  3580. local subcommands="
  3581. create
  3582. inspect
  3583. ls
  3584. prune
  3585. rm
  3586. "
  3587. __docker_subcommands "$subcommands" && return
  3588. case "$cur" in
  3589. -*)
  3590. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3591. ;;
  3592. *)
  3593. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3594. ;;
  3595. esac
  3596. }
  3597. _docker_wait() {
  3598. _docker_container_wait
  3599. }
  3600. _docker() {
  3601. local previous_extglob_setting=$(shopt -p extglob)
  3602. shopt -s extglob
  3603. local commands=(
  3604. attach
  3605. build
  3606. commit
  3607. container
  3608. cp
  3609. create
  3610. diff
  3611. events
  3612. exec
  3613. export
  3614. history
  3615. image
  3616. images
  3617. import
  3618. info
  3619. inspect
  3620. kill
  3621. load
  3622. login
  3623. logout
  3624. logs
  3625. network
  3626. node
  3627. pause
  3628. plugin
  3629. port
  3630. ps
  3631. pull
  3632. push
  3633. rename
  3634. restart
  3635. rm
  3636. rmi
  3637. run
  3638. save
  3639. search
  3640. secret
  3641. service
  3642. stack
  3643. start
  3644. stats
  3645. stop
  3646. swarm
  3647. system
  3648. tag
  3649. top
  3650. unpause
  3651. update
  3652. version
  3653. volume
  3654. wait
  3655. )
  3656. local experimental_commands=(
  3657. deploy
  3658. )
  3659. # These options are valid as global options for all client commands
  3660. # and valid as command options for `docker daemon`
  3661. local global_boolean_options="
  3662. --debug -D
  3663. --tls
  3664. --tlsverify
  3665. "
  3666. local global_options_with_args="
  3667. --config
  3668. --host -H
  3669. --log-level -l
  3670. --tlscacert
  3671. --tlscert
  3672. --tlskey
  3673. "
  3674. local host config
  3675. COMPREPLY=()
  3676. local cur prev words cword
  3677. _get_comp_words_by_ref -n : cur prev words cword
  3678. local command='docker' command_pos=0 subcommand_pos
  3679. local counter=1
  3680. while [ $counter -lt $cword ]; do
  3681. case "${words[$counter]}" in
  3682. # save host so that completion can use custom daemon
  3683. --host|-H)
  3684. (( counter++ ))
  3685. host="${words[$counter]}"
  3686. ;;
  3687. # save config so that completion can use custom configuration directories
  3688. --config)
  3689. (( counter++ ))
  3690. config="${words[$counter]}"
  3691. ;;
  3692. $(__docker_to_extglob "$global_options_with_args") )
  3693. (( counter++ ))
  3694. ;;
  3695. -*)
  3696. ;;
  3697. =)
  3698. (( counter++ ))
  3699. ;;
  3700. *)
  3701. command="${words[$counter]}"
  3702. command_pos=$counter
  3703. break
  3704. ;;
  3705. esac
  3706. (( counter++ ))
  3707. done
  3708. local binary="${words[0]}"
  3709. if [[ $binary == ?(*/)dockerd ]] ; then
  3710. # for the dockerd binary, we reuse completion of `docker daemon`.
  3711. # dockerd does not have subcommands and global options.
  3712. command=daemon
  3713. command_pos=0
  3714. fi
  3715. local completions_func=_docker_${command}
  3716. declare -F $completions_func >/dev/null && $completions_func
  3717. eval "$previous_extglob_setting"
  3718. return 0
  3719. }
  3720. eval "$__docker_previous_extglob_setting"
  3721. unset __docker_previous_extglob_setting
  3722. complete -F _docker docker dockerd