docker 89 KB

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