docker 89 KB

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