docker 90 KB

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