docker 91 KB

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