docker 79 KB

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