docker 80 KB

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