docker 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141
  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 --format "{{range \$i, \$p := .Plugins.$type}}{{.}} {{end}}"))
  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 "$prev" in
  1122. --filter)
  1123. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  1124. __docker_nospace
  1125. return
  1126. ;;
  1127. esac
  1128. case "$cur" in
  1129. -*)
  1130. COMPREPLY=( $( compgen -W "--force -f --filter --help" -- "$cur" ) )
  1131. ;;
  1132. esac
  1133. }
  1134. _docker_container_ps() {
  1135. _docker_container_ls
  1136. }
  1137. _docker_container_rename() {
  1138. case "$cur" in
  1139. -*)
  1140. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1141. ;;
  1142. *)
  1143. local counter=$(__docker_pos_first_nonflag)
  1144. if [ $cword -eq $counter ]; then
  1145. __docker_complete_containers_all
  1146. fi
  1147. ;;
  1148. esac
  1149. }
  1150. _docker_container_restart() {
  1151. case "$prev" in
  1152. --time|-t)
  1153. return
  1154. ;;
  1155. esac
  1156. case "$cur" in
  1157. -*)
  1158. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1159. ;;
  1160. *)
  1161. __docker_complete_containers_all
  1162. ;;
  1163. esac
  1164. }
  1165. _docker_container_rm() {
  1166. case "$cur" in
  1167. -*)
  1168. COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) )
  1169. ;;
  1170. *)
  1171. for arg in "${COMP_WORDS[@]}"; do
  1172. case "$arg" in
  1173. --force|-f)
  1174. __docker_complete_containers_all
  1175. return
  1176. ;;
  1177. esac
  1178. done
  1179. __docker_complete_containers_stopped
  1180. ;;
  1181. esac
  1182. }
  1183. _docker_container_run() {
  1184. local options_with_args="
  1185. --add-host
  1186. --attach -a
  1187. --blkio-weight
  1188. --blkio-weight-device
  1189. --cap-add
  1190. --cap-drop
  1191. --cgroup-parent
  1192. --cidfile
  1193. --cpu-period
  1194. --cpu-quota
  1195. --cpu-rt-period
  1196. --cpu-rt-runtime
  1197. --cpuset-cpus
  1198. --cpus
  1199. --cpuset-mems
  1200. --cpu-shares -c
  1201. --device
  1202. --device-read-bps
  1203. --device-read-iops
  1204. --device-write-bps
  1205. --device-write-iops
  1206. --dns
  1207. --dns-option
  1208. --dns-search
  1209. --entrypoint
  1210. --env -e
  1211. --env-file
  1212. --expose
  1213. --group-add
  1214. --hostname -h
  1215. --ip
  1216. --ip6
  1217. --ipc
  1218. --isolation
  1219. --kernel-memory
  1220. --label-file
  1221. --label -l
  1222. --link
  1223. --link-local-ip
  1224. --log-driver
  1225. --log-opt
  1226. --mac-address
  1227. --memory -m
  1228. --memory-swap
  1229. --memory-swappiness
  1230. --memory-reservation
  1231. --name
  1232. --network
  1233. --network-alias
  1234. --oom-score-adj
  1235. --pid
  1236. --pids-limit
  1237. --publish -p
  1238. --restart
  1239. --runtime
  1240. --security-opt
  1241. --shm-size
  1242. --stop-signal
  1243. --stop-timeout
  1244. --storage-opt
  1245. --tmpfs
  1246. --sysctl
  1247. --ulimit
  1248. --user -u
  1249. --userns
  1250. --uts
  1251. --volume-driver
  1252. --volumes-from
  1253. --volume -v
  1254. --workdir -w
  1255. "
  1256. local boolean_options="
  1257. --disable-content-trust=false
  1258. --help
  1259. --init
  1260. --interactive -i
  1261. --oom-kill-disable
  1262. --privileged
  1263. --publish-all -P
  1264. --read-only
  1265. --tty -t
  1266. "
  1267. if [ "$command" = "run" -o "$subcommand" = "run" ] ; then
  1268. options_with_args="$options_with_args
  1269. --detach-keys
  1270. --health-cmd
  1271. --health-interval
  1272. --health-retries
  1273. --health-timeout
  1274. "
  1275. boolean_options="$boolean_options
  1276. --detach -d
  1277. --no-healthcheck
  1278. --rm
  1279. --sig-proxy=false
  1280. "
  1281. __docker_complete_detach-keys && return
  1282. fi
  1283. local all_options="$options_with_args $boolean_options"
  1284. __docker_complete_log_driver_options && return
  1285. __docker_complete_restart && return
  1286. local key=$(__docker_map_key_of_current_option '--security-opt')
  1287. case "$key" in
  1288. label)
  1289. [[ $cur == *: ]] && return
  1290. COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") )
  1291. if [ "${COMPREPLY[*]}" != "disable" ] ; then
  1292. __docker_nospace
  1293. fi
  1294. return
  1295. ;;
  1296. seccomp)
  1297. local cur=${cur##*=}
  1298. _filedir
  1299. COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) )
  1300. return
  1301. ;;
  1302. esac
  1303. case "$prev" in
  1304. --add-host)
  1305. case "$cur" in
  1306. *:)
  1307. __docker_complete_resolved_hostname
  1308. return
  1309. ;;
  1310. esac
  1311. ;;
  1312. --attach|-a)
  1313. COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
  1314. return
  1315. ;;
  1316. --cap-add|--cap-drop)
  1317. __docker_complete_capabilities
  1318. return
  1319. ;;
  1320. --cidfile|--env-file|--label-file)
  1321. _filedir
  1322. return
  1323. ;;
  1324. --device|--tmpfs|--volume|-v)
  1325. case "$cur" in
  1326. *:*)
  1327. # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
  1328. ;;
  1329. '')
  1330. COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
  1331. __docker_nospace
  1332. ;;
  1333. /*)
  1334. _filedir
  1335. __docker_nospace
  1336. ;;
  1337. esac
  1338. return
  1339. ;;
  1340. --env|-e)
  1341. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  1342. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1343. __docker_nospace
  1344. return
  1345. ;;
  1346. --ipc)
  1347. case "$cur" in
  1348. *:*)
  1349. cur="${cur#*:}"
  1350. __docker_complete_containers_running
  1351. ;;
  1352. *)
  1353. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1354. if [ "$COMPREPLY" = "container:" ]; then
  1355. __docker_nospace
  1356. fi
  1357. ;;
  1358. esac
  1359. return
  1360. ;;
  1361. --isolation)
  1362. __docker_complete_isolation
  1363. return
  1364. ;;
  1365. --link)
  1366. case "$cur" in
  1367. *:*)
  1368. ;;
  1369. *)
  1370. __docker_complete_containers_running
  1371. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  1372. __docker_nospace
  1373. ;;
  1374. esac
  1375. return
  1376. ;;
  1377. --log-driver)
  1378. __docker_complete_log_drivers
  1379. return
  1380. ;;
  1381. --log-opt)
  1382. __docker_complete_log_options
  1383. return
  1384. ;;
  1385. --network)
  1386. case "$cur" in
  1387. container:*)
  1388. __docker_complete_containers_all --cur "${cur#*:}"
  1389. ;;
  1390. *)
  1391. COMPREPLY=( $( compgen -W "$(__docker_plugins_bundled --type Network) $(__docker_networks) container:" -- "$cur") )
  1392. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1393. __docker_nospace
  1394. fi
  1395. ;;
  1396. esac
  1397. return
  1398. ;;
  1399. --pid)
  1400. case "$cur" in
  1401. *:*)
  1402. __docker_complete_containers_running --cur "${cur#*:}"
  1403. ;;
  1404. *)
  1405. COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) )
  1406. if [ "$COMPREPLY" = "container:" ]; then
  1407. __docker_nospace
  1408. fi
  1409. ;;
  1410. esac
  1411. return
  1412. ;;
  1413. --runtime)
  1414. __docker_complete_runtimes
  1415. return
  1416. ;;
  1417. --security-opt)
  1418. COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") )
  1419. if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then
  1420. __docker_nospace
  1421. fi
  1422. return
  1423. ;;
  1424. --storage-opt)
  1425. COMPREPLY=( $( compgen -W "size" -S = -- "$cur") )
  1426. __docker_nospace
  1427. return
  1428. ;;
  1429. --user|-u)
  1430. __docker_complete_user_group
  1431. return
  1432. ;;
  1433. --userns)
  1434. COMPREPLY=( $( compgen -W "host" -- "$cur" ) )
  1435. return
  1436. ;;
  1437. --volume-driver)
  1438. __docker_complete_plugins_bundled --type Volume
  1439. return
  1440. ;;
  1441. --volumes-from)
  1442. __docker_complete_containers_all
  1443. return
  1444. ;;
  1445. $(__docker_to_extglob "$options_with_args") )
  1446. return
  1447. ;;
  1448. esac
  1449. case "$cur" in
  1450. -*)
  1451. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1452. ;;
  1453. *)
  1454. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1455. if [ $cword -eq $counter ]; then
  1456. __docker_complete_images
  1457. fi
  1458. ;;
  1459. esac
  1460. }
  1461. _docker_container_start() {
  1462. __docker_complete_detach-keys && return
  1463. case "$cur" in
  1464. -*)
  1465. COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
  1466. ;;
  1467. *)
  1468. __docker_complete_containers_stopped
  1469. ;;
  1470. esac
  1471. }
  1472. _docker_container_stats() {
  1473. case "$prev" in
  1474. --format)
  1475. return
  1476. ;;
  1477. esac
  1478. case "$cur" in
  1479. -*)
  1480. COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) )
  1481. ;;
  1482. *)
  1483. __docker_complete_containers_running
  1484. ;;
  1485. esac
  1486. }
  1487. _docker_container_stop() {
  1488. case "$prev" in
  1489. --time|-t)
  1490. return
  1491. ;;
  1492. esac
  1493. case "$cur" in
  1494. -*)
  1495. COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) )
  1496. ;;
  1497. *)
  1498. __docker_complete_containers_running
  1499. ;;
  1500. esac
  1501. }
  1502. _docker_container_top() {
  1503. case "$cur" in
  1504. -*)
  1505. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1506. ;;
  1507. *)
  1508. local counter=$(__docker_pos_first_nonflag)
  1509. if [ $cword -eq $counter ]; then
  1510. __docker_complete_containers_running
  1511. fi
  1512. ;;
  1513. esac
  1514. }
  1515. _docker_container_unpause() {
  1516. case "$cur" in
  1517. -*)
  1518. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1519. ;;
  1520. *)
  1521. local counter=$(__docker_pos_first_nonflag)
  1522. if [ $cword -eq $counter ]; then
  1523. __docker_complete_containers_unpauseable
  1524. fi
  1525. ;;
  1526. esac
  1527. }
  1528. _docker_container_update() {
  1529. local options_with_args="
  1530. --blkio-weight
  1531. --cpu-period
  1532. --cpu-quota
  1533. --cpu-rt-period
  1534. --cpu-rt-runtime
  1535. --cpuset-cpus
  1536. --cpuset-mems
  1537. --cpu-shares -c
  1538. --kernel-memory
  1539. --memory -m
  1540. --memory-reservation
  1541. --memory-swap
  1542. --restart
  1543. "
  1544. local boolean_options="
  1545. --help
  1546. "
  1547. local all_options="$options_with_args $boolean_options"
  1548. __docker_complete_restart && return
  1549. case "$prev" in
  1550. $(__docker_to_extglob "$options_with_args") )
  1551. return
  1552. ;;
  1553. esac
  1554. case "$cur" in
  1555. -*)
  1556. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1557. ;;
  1558. *)
  1559. __docker_complete_containers_all
  1560. ;;
  1561. esac
  1562. }
  1563. _docker_container_wait() {
  1564. case "$cur" in
  1565. -*)
  1566. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1567. ;;
  1568. *)
  1569. __docker_complete_containers_all
  1570. ;;
  1571. esac
  1572. }
  1573. _docker_commit() {
  1574. _docker_container_commit
  1575. }
  1576. _docker_cp() {
  1577. _docker_container_cp
  1578. }
  1579. _docker_create() {
  1580. _docker_container_run
  1581. }
  1582. _docker_daemon() {
  1583. local boolean_options="
  1584. $global_boolean_options
  1585. --disable-legacy-registry
  1586. --experimental
  1587. --help
  1588. --icc=false
  1589. --init
  1590. --ip-forward=false
  1591. --ip-masq=false
  1592. --iptables=false
  1593. --ipv6
  1594. --live-restore
  1595. --raw-logs
  1596. --selinux-enabled
  1597. --userland-proxy=false
  1598. "
  1599. local options_with_args="
  1600. $global_options_with_args
  1601. --add-runtime
  1602. --api-cors-header
  1603. --authorization-plugin
  1604. --bip
  1605. --bridge -b
  1606. --cgroup-parent
  1607. --cluster-advertise
  1608. --cluster-store
  1609. --cluster-store-opt
  1610. --config-file
  1611. --containerd
  1612. --default-gateway
  1613. --default-gateway-v6
  1614. --default-ulimit
  1615. --dns
  1616. --dns-search
  1617. --dns-opt
  1618. --exec-opt
  1619. --exec-root
  1620. --fixed-cidr
  1621. --fixed-cidr-v6
  1622. --graph -g
  1623. --group -G
  1624. --init-path
  1625. --insecure-registry
  1626. --ip
  1627. --label
  1628. --log-driver
  1629. --log-opt
  1630. --max-concurrent-downloads
  1631. --max-concurrent-uploads
  1632. --mtu
  1633. --oom-score-adjust
  1634. --pidfile -p
  1635. --registry-mirror
  1636. --seccomp-profile
  1637. --shutdown-timeout
  1638. --storage-driver -s
  1639. --storage-opt
  1640. --userland-proxy-path
  1641. --userns-remap
  1642. "
  1643. __docker_complete_log_driver_options && return
  1644. key=$(__docker_map_key_of_current_option '--cluster-store-opt')
  1645. case "$key" in
  1646. kv.*file)
  1647. cur=${cur##*=}
  1648. _filedir
  1649. return
  1650. ;;
  1651. esac
  1652. local key=$(__docker_map_key_of_current_option '--storage-opt')
  1653. case "$key" in
  1654. dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion)
  1655. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1656. return
  1657. ;;
  1658. dm.fs)
  1659. COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) )
  1660. return
  1661. ;;
  1662. dm.thinpooldev)
  1663. cur=${cur##*=}
  1664. _filedir
  1665. return
  1666. ;;
  1667. esac
  1668. case "$prev" in
  1669. --authorization-plugin)
  1670. __docker_complete_plugins_bundled --type Authorization
  1671. return
  1672. ;;
  1673. --cluster-store)
  1674. COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) )
  1675. __docker_nospace
  1676. return
  1677. ;;
  1678. --cluster-store-opt)
  1679. COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) )
  1680. __docker_nospace
  1681. return
  1682. ;;
  1683. --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey|--userland-proxy-path)
  1684. _filedir
  1685. return
  1686. ;;
  1687. --exec-root|--graph|-g)
  1688. _filedir -d
  1689. return
  1690. ;;
  1691. --log-driver)
  1692. __docker_complete_log_drivers
  1693. return
  1694. ;;
  1695. --storage-driver|-s)
  1696. COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) )
  1697. return
  1698. ;;
  1699. --storage-opt)
  1700. local btrfs_options="btrfs.min_space"
  1701. local devicemapper_options="
  1702. dm.basesize
  1703. dm.blkdiscard
  1704. dm.blocksize
  1705. dm.fs
  1706. dm.loopdatasize
  1707. dm.loopmetadatasize
  1708. dm.min_free_space
  1709. dm.mkfsarg
  1710. dm.mountopt
  1711. dm.override_udev_sync_check
  1712. dm.thinpooldev
  1713. dm.use_deferred_deletion
  1714. dm.use_deferred_removal
  1715. "
  1716. local zfs_options="zfs.fsname"
  1717. case $(__docker_value_of_option '--storage-driver|-s') in
  1718. '')
  1719. COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) )
  1720. ;;
  1721. btrfs)
  1722. COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) )
  1723. ;;
  1724. devicemapper)
  1725. COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) )
  1726. ;;
  1727. zfs)
  1728. COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) )
  1729. ;;
  1730. *)
  1731. return
  1732. ;;
  1733. esac
  1734. __docker_nospace
  1735. return
  1736. ;;
  1737. --log-level|-l)
  1738. __docker_complete_log_levels
  1739. return
  1740. ;;
  1741. --log-opt)
  1742. __docker_complete_log_options
  1743. return
  1744. ;;
  1745. --seccomp-profile)
  1746. _filedir json
  1747. return
  1748. ;;
  1749. --userns-remap)
  1750. __docker_complete_user_group
  1751. return
  1752. ;;
  1753. $(__docker_to_extglob "$options_with_args") )
  1754. return
  1755. ;;
  1756. esac
  1757. case "$cur" in
  1758. -*)
  1759. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  1760. ;;
  1761. esac
  1762. }
  1763. _docker_deploy() {
  1764. __docker_is_experimental && _docker_stack_deploy
  1765. }
  1766. _docker_diff() {
  1767. _docker_container_diff
  1768. }
  1769. _docker_events() {
  1770. _docker_system_events
  1771. }
  1772. _docker_exec() {
  1773. _docker_container_exec
  1774. }
  1775. _docker_export() {
  1776. _docker_container_export
  1777. }
  1778. _docker_help() {
  1779. local counter=$(__docker_pos_first_nonflag)
  1780. if [ $cword -eq $counter ]; then
  1781. COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
  1782. fi
  1783. }
  1784. _docker_history() {
  1785. _docker_image_history
  1786. }
  1787. _docker_image() {
  1788. local subcommands="
  1789. build
  1790. history
  1791. import
  1792. inspect
  1793. load
  1794. ls
  1795. prune
  1796. pull
  1797. push
  1798. rm
  1799. save
  1800. tag
  1801. "
  1802. local aliases="
  1803. images
  1804. list
  1805. remove
  1806. rmi
  1807. "
  1808. __docker_subcommands "$subcommands $aliases" && return
  1809. case "$cur" in
  1810. -*)
  1811. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  1812. ;;
  1813. *)
  1814. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  1815. ;;
  1816. esac
  1817. }
  1818. _docker_image_build() {
  1819. local options_with_args="
  1820. --build-arg
  1821. --cache-from
  1822. --cgroup-parent
  1823. --cpuset-cpus
  1824. --cpuset-mems
  1825. --cpu-shares -c
  1826. --cpu-period
  1827. --cpu-quota
  1828. --file -f
  1829. --isolation
  1830. --label
  1831. --memory -m
  1832. --memory-swap
  1833. --network
  1834. --shm-size
  1835. --tag -t
  1836. --ulimit
  1837. "
  1838. local boolean_options="
  1839. --compress
  1840. --disable-content-trust=false
  1841. --force-rm
  1842. --help
  1843. --no-cache
  1844. --pull
  1845. --quiet -q
  1846. --rm
  1847. "
  1848. __docker_is_experimental && boolean_options+="--squash"
  1849. local all_options="$options_with_args $boolean_options"
  1850. case "$prev" in
  1851. --build-arg)
  1852. COMPREPLY=( $( compgen -e -- "$cur" ) )
  1853. __docker_nospace
  1854. return
  1855. ;;
  1856. --cache-from)
  1857. __docker_complete_image_repos_and_tags
  1858. return
  1859. ;;
  1860. --file|-f)
  1861. _filedir
  1862. return
  1863. ;;
  1864. --isolation)
  1865. __docker_complete_isolation
  1866. return
  1867. ;;
  1868. --network)
  1869. case "$cur" in
  1870. container:*)
  1871. __docker_complete_containers_all --cur "${cur#*:}"
  1872. ;;
  1873. *)
  1874. COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") )
  1875. if [ "${COMPREPLY[*]}" = "container:" ] ; then
  1876. __docker_nospace
  1877. fi
  1878. ;;
  1879. esac
  1880. return
  1881. ;;
  1882. --tag|-t)
  1883. __docker_complete_image_repos_and_tags
  1884. return
  1885. ;;
  1886. $(__docker_to_extglob "$options_with_args") )
  1887. return
  1888. ;;
  1889. esac
  1890. case "$cur" in
  1891. -*)
  1892. COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
  1893. ;;
  1894. *)
  1895. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  1896. if [ $cword -eq $counter ]; then
  1897. _filedir -d
  1898. fi
  1899. ;;
  1900. esac
  1901. }
  1902. _docker_image_history() {
  1903. case "$cur" in
  1904. -*)
  1905. COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) )
  1906. ;;
  1907. *)
  1908. local counter=$(__docker_pos_first_nonflag)
  1909. if [ $cword -eq $counter ]; then
  1910. __docker_complete_images
  1911. fi
  1912. ;;
  1913. esac
  1914. }
  1915. _docker_image_images() {
  1916. _docker_image_ls
  1917. }
  1918. _docker_image_import() {
  1919. case "$prev" in
  1920. --change|-c|--message|-m)
  1921. return
  1922. ;;
  1923. esac
  1924. case "$cur" in
  1925. -*)
  1926. COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) )
  1927. ;;
  1928. *)
  1929. local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m')
  1930. if [ $cword -eq $counter ]; then
  1931. return
  1932. fi
  1933. (( counter++ ))
  1934. if [ $cword -eq $counter ]; then
  1935. __docker_complete_image_repos_and_tags
  1936. return
  1937. fi
  1938. ;;
  1939. esac
  1940. }
  1941. _docker_image_inspect() {
  1942. _docker_inspect --type image
  1943. }
  1944. _docker_image_load() {
  1945. case "$prev" in
  1946. --input|-i)
  1947. _filedir
  1948. return
  1949. ;;
  1950. esac
  1951. case "$cur" in
  1952. -*)
  1953. COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) )
  1954. ;;
  1955. esac
  1956. }
  1957. _docker_image_list() {
  1958. _docker_image_ls
  1959. }
  1960. _docker_image_ls() {
  1961. local key=$(__docker_map_key_of_current_option '--filter|-f')
  1962. case "$key" in
  1963. before|since|reference)
  1964. cur="${cur##*=}"
  1965. __docker_complete_images
  1966. return
  1967. ;;
  1968. dangling)
  1969. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  1970. return
  1971. ;;
  1972. label)
  1973. return
  1974. ;;
  1975. esac
  1976. case "$prev" in
  1977. --filter|-f)
  1978. COMPREPLY=( $( compgen -S = -W "before dangling label reference since" -- "$cur" ) )
  1979. __docker_nospace
  1980. return
  1981. ;;
  1982. --format)
  1983. return
  1984. ;;
  1985. esac
  1986. case "$cur" in
  1987. -*)
  1988. COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  1989. ;;
  1990. =)
  1991. return
  1992. ;;
  1993. *)
  1994. __docker_complete_image_repos
  1995. ;;
  1996. esac
  1997. }
  1998. _docker_image_prune() {
  1999. case "$prev" in
  2000. --filter)
  2001. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  2002. __docker_nospace
  2003. return
  2004. ;;
  2005. esac
  2006. case "$cur" in
  2007. -*)
  2008. COMPREPLY=( $( compgen -W "--all -a --force -f --filter --help" -- "$cur" ) )
  2009. ;;
  2010. esac
  2011. }
  2012. _docker_image_pull() {
  2013. case "$cur" in
  2014. -*)
  2015. COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) )
  2016. ;;
  2017. *)
  2018. local counter=$(__docker_pos_first_nonflag)
  2019. if [ $cword -eq $counter ]; then
  2020. for arg in "${COMP_WORDS[@]}"; do
  2021. case "$arg" in
  2022. --all-tags|-a)
  2023. __docker_complete_image_repos
  2024. return
  2025. ;;
  2026. esac
  2027. done
  2028. __docker_complete_image_repos_and_tags
  2029. fi
  2030. ;;
  2031. esac
  2032. }
  2033. _docker_image_push() {
  2034. case "$cur" in
  2035. -*)
  2036. COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) )
  2037. ;;
  2038. *)
  2039. local counter=$(__docker_pos_first_nonflag)
  2040. if [ $cword -eq $counter ]; then
  2041. __docker_complete_image_repos_and_tags
  2042. fi
  2043. ;;
  2044. esac
  2045. }
  2046. _docker_image_remove() {
  2047. _docker_image_rm
  2048. }
  2049. _docker_image_rm() {
  2050. case "$cur" in
  2051. -*)
  2052. COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) )
  2053. ;;
  2054. *)
  2055. __docker_complete_images
  2056. ;;
  2057. esac
  2058. }
  2059. _docker_image_rmi() {
  2060. _docker_image_rm
  2061. }
  2062. _docker_image_save() {
  2063. case "$prev" in
  2064. --output|-o)
  2065. _filedir
  2066. return
  2067. ;;
  2068. esac
  2069. case "$cur" in
  2070. -*)
  2071. COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) )
  2072. ;;
  2073. *)
  2074. __docker_complete_images
  2075. ;;
  2076. esac
  2077. }
  2078. _docker_image_tag() {
  2079. case "$cur" in
  2080. -*)
  2081. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2082. ;;
  2083. *)
  2084. local counter=$(__docker_pos_first_nonflag)
  2085. if [ $cword -eq $counter ]; then
  2086. __docker_complete_image_repos_and_tags
  2087. return
  2088. fi
  2089. (( counter++ ))
  2090. if [ $cword -eq $counter ]; then
  2091. __docker_complete_image_repos_and_tags
  2092. return
  2093. fi
  2094. ;;
  2095. esac
  2096. }
  2097. _docker_images() {
  2098. _docker_image_ls
  2099. }
  2100. _docker_import() {
  2101. _docker_image_import
  2102. }
  2103. _docker_info() {
  2104. _docker_system_info
  2105. }
  2106. _docker_inspect() {
  2107. local preselected_type
  2108. local type
  2109. if [ "$1" = "--type" ] ; then
  2110. preselected_type=yes
  2111. type="$2"
  2112. else
  2113. type=$(__docker_value_of_option --type)
  2114. fi
  2115. case "$prev" in
  2116. --format|-f)
  2117. return
  2118. ;;
  2119. --type)
  2120. if [ -z "$preselected_type" ] ; then
  2121. COMPREPLY=( $( compgen -W "container image network node plugin service volume" -- "$cur" ) )
  2122. return
  2123. fi
  2124. ;;
  2125. esac
  2126. case "$cur" in
  2127. -*)
  2128. local options="--format -f --help --size -s"
  2129. if [ -z "$preselected_type" ] ; then
  2130. options+=" --type"
  2131. fi
  2132. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  2133. ;;
  2134. *)
  2135. case "$type" in
  2136. '')
  2137. COMPREPLY=( $( compgen -W "
  2138. $(__docker_containers --all)
  2139. $(__docker_images)
  2140. $(__docker_networks)
  2141. $(__docker_nodes)
  2142. $(__docker_plugins_installed)
  2143. $(__docker_services)
  2144. $(__docker_volumes)
  2145. " -- "$cur" ) )
  2146. ;;
  2147. container)
  2148. __docker_complete_containers_all
  2149. ;;
  2150. image)
  2151. __docker_complete_images
  2152. ;;
  2153. network)
  2154. __docker_complete_networks
  2155. ;;
  2156. node)
  2157. __docker_complete_nodes
  2158. ;;
  2159. plugin)
  2160. __docker_complete_plugins_installed
  2161. ;;
  2162. service)
  2163. __docker_complete_services
  2164. ;;
  2165. volume)
  2166. __docker_complete_volumes
  2167. ;;
  2168. esac
  2169. esac
  2170. }
  2171. _docker_kill() {
  2172. _docker_container_kill
  2173. }
  2174. _docker_load() {
  2175. _docker_image_load
  2176. }
  2177. _docker_login() {
  2178. case "$prev" in
  2179. --password|-p|--username|-u)
  2180. return
  2181. ;;
  2182. esac
  2183. case "$cur" in
  2184. -*)
  2185. COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) )
  2186. ;;
  2187. esac
  2188. }
  2189. _docker_logout() {
  2190. case "$cur" in
  2191. -*)
  2192. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2193. ;;
  2194. esac
  2195. }
  2196. _docker_logs() {
  2197. _docker_container_logs
  2198. }
  2199. _docker_network_connect() {
  2200. local options_with_args="
  2201. --alias
  2202. --ip
  2203. --ip6
  2204. --link
  2205. --link-local-ip
  2206. "
  2207. local boolean_options="
  2208. --help
  2209. "
  2210. case "$prev" in
  2211. --link)
  2212. case "$cur" in
  2213. *:*)
  2214. ;;
  2215. *)
  2216. __docker_complete_containers_running
  2217. COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
  2218. __docker_nospace
  2219. ;;
  2220. esac
  2221. return
  2222. ;;
  2223. $(__docker_to_extglob "$options_with_args") )
  2224. return
  2225. ;;
  2226. esac
  2227. case "$cur" in
  2228. -*)
  2229. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2230. ;;
  2231. *)
  2232. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2233. if [ $cword -eq $counter ]; then
  2234. __docker_complete_networks
  2235. elif [ $cword -eq $(($counter + 1)) ]; then
  2236. __docker_complete_containers_all
  2237. fi
  2238. ;;
  2239. esac
  2240. }
  2241. _docker_network_create() {
  2242. case "$prev" in
  2243. --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet)
  2244. return
  2245. ;;
  2246. --ipam-driver)
  2247. COMPREPLY=( $( compgen -W "default" -- "$cur" ) )
  2248. return
  2249. ;;
  2250. --driver|-d)
  2251. # remove drivers that allow one instance only, add drivers missing in `docker info`
  2252. __docker_complete_plugins_bundled --type Network --remove host --remove null --add macvlan
  2253. return
  2254. ;;
  2255. --label)
  2256. return
  2257. ;;
  2258. esac
  2259. case "$cur" in
  2260. -*)
  2261. COMPREPLY=( $( compgen -W "--attachable --aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) )
  2262. ;;
  2263. esac
  2264. }
  2265. _docker_network_disconnect() {
  2266. case "$cur" in
  2267. -*)
  2268. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2269. ;;
  2270. *)
  2271. local counter=$(__docker_pos_first_nonflag)
  2272. if [ $cword -eq $counter ]; then
  2273. __docker_complete_networks
  2274. elif [ $cword -eq $(($counter + 1)) ]; then
  2275. __docker_complete_containers_in_network "$prev"
  2276. fi
  2277. ;;
  2278. esac
  2279. }
  2280. _docker_network_inspect() {
  2281. case "$prev" in
  2282. --format|-f)
  2283. return
  2284. ;;
  2285. esac
  2286. case "$cur" in
  2287. -*)
  2288. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  2289. ;;
  2290. *)
  2291. __docker_complete_networks
  2292. esac
  2293. }
  2294. _docker_network_ls() {
  2295. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2296. case "$key" in
  2297. driver)
  2298. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Network --add macvlan
  2299. return
  2300. ;;
  2301. id)
  2302. __docker_complete_networks --cur "${cur##*=}" --id
  2303. return
  2304. ;;
  2305. name)
  2306. __docker_complete_networks --cur "${cur##*=}" --name
  2307. return
  2308. ;;
  2309. type)
  2310. COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) )
  2311. return
  2312. ;;
  2313. esac
  2314. case "$prev" in
  2315. --filter|-f)
  2316. COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) )
  2317. __docker_nospace
  2318. return
  2319. ;;
  2320. --format)
  2321. return
  2322. ;;
  2323. esac
  2324. case "$cur" in
  2325. -*)
  2326. COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) )
  2327. ;;
  2328. esac
  2329. }
  2330. _docker_network_prune() {
  2331. case "$prev" in
  2332. --filter)
  2333. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  2334. __docker_nospace
  2335. return
  2336. ;;
  2337. esac
  2338. case "$cur" in
  2339. -*)
  2340. COMPREPLY=( $( compgen -W "--force -f --filter --help" -- "$cur" ) )
  2341. ;;
  2342. esac
  2343. }
  2344. _docker_network_rm() {
  2345. case "$cur" in
  2346. -*)
  2347. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2348. ;;
  2349. *)
  2350. __docker_complete_networks --filter type=custom
  2351. esac
  2352. }
  2353. _docker_network() {
  2354. local subcommands="
  2355. connect
  2356. create
  2357. disconnect
  2358. inspect
  2359. ls
  2360. prune
  2361. rm
  2362. "
  2363. __docker_subcommands "$subcommands" && return
  2364. case "$cur" in
  2365. -*)
  2366. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2367. ;;
  2368. *)
  2369. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2370. ;;
  2371. esac
  2372. }
  2373. _docker_service() {
  2374. local subcommands="
  2375. create
  2376. inspect
  2377. ls list
  2378. rm remove
  2379. scale
  2380. ps
  2381. update
  2382. "
  2383. __docker_subcommands "$subcommands" && return
  2384. case "$cur" in
  2385. -*)
  2386. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2387. ;;
  2388. *)
  2389. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2390. ;;
  2391. esac
  2392. }
  2393. _docker_service_create() {
  2394. _docker_service_update
  2395. }
  2396. _docker_service_inspect() {
  2397. case "$prev" in
  2398. --format|-f)
  2399. return
  2400. ;;
  2401. esac
  2402. case "$cur" in
  2403. -*)
  2404. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2405. ;;
  2406. *)
  2407. __docker_complete_services
  2408. esac
  2409. }
  2410. _docker_service_list() {
  2411. _docker_service_ls
  2412. }
  2413. _docker_service_ls() {
  2414. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2415. case "$key" in
  2416. id)
  2417. __docker_complete_services --cur "${cur##*=}" --id
  2418. return
  2419. ;;
  2420. name)
  2421. __docker_complete_services --cur "${cur##*=}" --name
  2422. return
  2423. ;;
  2424. esac
  2425. case "$prev" in
  2426. --filter|-f)
  2427. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2428. __docker_nospace
  2429. return
  2430. ;;
  2431. esac
  2432. case "$cur" in
  2433. -*)
  2434. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2435. ;;
  2436. esac
  2437. }
  2438. _docker_service_remove() {
  2439. _docker_service_rm
  2440. }
  2441. _docker_service_rm() {
  2442. case "$cur" in
  2443. -*)
  2444. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2445. ;;
  2446. *)
  2447. __docker_complete_services
  2448. esac
  2449. }
  2450. _docker_service_scale() {
  2451. case "$cur" in
  2452. -*)
  2453. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2454. ;;
  2455. *)
  2456. __docker_complete_services
  2457. __docker_append_to_completions "="
  2458. __docker_nospace
  2459. ;;
  2460. esac
  2461. }
  2462. _docker_service_ps() {
  2463. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2464. case "$key" in
  2465. desired-state)
  2466. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2467. return
  2468. ;;
  2469. name)
  2470. __docker_complete_services --cur "${cur##*=}" --name
  2471. return
  2472. ;;
  2473. esac
  2474. case "$prev" in
  2475. --filter|-f)
  2476. COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) )
  2477. __docker_nospace
  2478. return
  2479. ;;
  2480. esac
  2481. case "$cur" in
  2482. -*)
  2483. COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) )
  2484. ;;
  2485. *)
  2486. __docker_complete_services
  2487. ;;
  2488. esac
  2489. }
  2490. _docker_service_update() {
  2491. local $subcommand="${words[$subcommand_pos]}"
  2492. local options_with_args="
  2493. --constraint
  2494. --endpoint-mode
  2495. --env -e
  2496. --force
  2497. --health-cmd
  2498. --health-interval
  2499. --health-retries
  2500. --health-timeout
  2501. --hostname
  2502. --label -l
  2503. --limit-cpu
  2504. --limit-memory
  2505. --log-driver
  2506. --log-opt
  2507. --mount
  2508. --network
  2509. --no-healthcheck
  2510. --publish -p
  2511. --replicas
  2512. --reserve-cpu
  2513. --reserve-memory
  2514. --restart-condition
  2515. --restart-delay
  2516. --restart-max-attempts
  2517. --restart-window
  2518. --rollback
  2519. --stop-grace-period
  2520. --update-delay
  2521. --update-failure-action
  2522. --update-max-failure-ratio
  2523. --update-monitor
  2524. --update-parallelism
  2525. --user -u
  2526. --workdir -w
  2527. "
  2528. local boolean_options="
  2529. --help
  2530. --tty -t
  2531. --with-registry-auth
  2532. "
  2533. __docker_complete_log_driver_options && return
  2534. if [ "$subcommand" = "create" ] ; then
  2535. options_with_args="$options_with_args
  2536. --container-label
  2537. --dns
  2538. --dns-option
  2539. --dns-search
  2540. --env-file
  2541. --group
  2542. --host
  2543. --mode
  2544. --name
  2545. --publish
  2546. --secret
  2547. "
  2548. case "$prev" in
  2549. --env-file)
  2550. _filedir
  2551. return
  2552. ;;
  2553. --group)
  2554. COMPREPLY=( $(compgen -g -- "$cur") )
  2555. return
  2556. ;;
  2557. --host)
  2558. case "$cur" in
  2559. *:)
  2560. __docker_complete_resolved_hostname
  2561. return
  2562. ;;
  2563. esac
  2564. ;;
  2565. --mode)
  2566. COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
  2567. return
  2568. ;;
  2569. --secret)
  2570. __docker_complete_secrets
  2571. return
  2572. ;;
  2573. esac
  2574. fi
  2575. if [ "$subcommand" = "update" ] ; then
  2576. options_with_args="$options_with_args
  2577. --arg
  2578. --container-label-add
  2579. --container-label-rm
  2580. --dns-add
  2581. --dns-option-add
  2582. --dns-option-rm
  2583. --dns-rm
  2584. --dns-search-add
  2585. --dns-search-rm
  2586. --group-add
  2587. --group-rm
  2588. --host-add
  2589. --host-rm
  2590. --image
  2591. --publish-add
  2592. --publish-rm
  2593. --secret-add
  2594. --secret-rm
  2595. "
  2596. case "$prev" in
  2597. --group-add|--group-rm)
  2598. COMPREPLY=( $(compgen -g -- "$cur") )
  2599. return
  2600. ;;
  2601. --host-add|--host-rm)
  2602. case "$cur" in
  2603. *:)
  2604. __docker_complete_resolved_hostname
  2605. return
  2606. ;;
  2607. esac
  2608. ;;
  2609. --image)
  2610. __docker_complete_image_repos_and_tags
  2611. return
  2612. ;;
  2613. --secret-add|--secret-rm)
  2614. __docker_complete_secrets
  2615. return
  2616. ;;
  2617. esac
  2618. fi
  2619. case "$prev" in
  2620. --endpoint-mode)
  2621. COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
  2622. return
  2623. ;;
  2624. --env|-e)
  2625. # we do not append a "=" here because "-e VARNAME" is legal systax, too
  2626. COMPREPLY=( $( compgen -e -- "$cur" ) )
  2627. __docker_nospace
  2628. return
  2629. ;;
  2630. --log-driver)
  2631. __docker_complete_log_drivers
  2632. return
  2633. ;;
  2634. --log-opt)
  2635. __docker_complete_log_options
  2636. return
  2637. ;;
  2638. --network)
  2639. __docker_complete_networks
  2640. return
  2641. ;;
  2642. --restart-condition)
  2643. COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
  2644. return
  2645. ;;
  2646. --user|-u)
  2647. __docker_complete_user_group
  2648. return
  2649. ;;
  2650. $(__docker_to_extglob "$options_with_args") )
  2651. return
  2652. ;;
  2653. esac
  2654. case "$cur" in
  2655. -*)
  2656. COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) )
  2657. ;;
  2658. *)
  2659. local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
  2660. if [ "$subcommand" = "update" ] ; then
  2661. if [ $cword -eq $counter ]; then
  2662. __docker_complete_services
  2663. fi
  2664. else
  2665. if [ $cword -eq $counter ]; then
  2666. __docker_complete_images
  2667. fi
  2668. fi
  2669. ;;
  2670. esac
  2671. }
  2672. _docker_swarm() {
  2673. local subcommands="
  2674. init
  2675. join
  2676. join-token
  2677. leave
  2678. update
  2679. "
  2680. __docker_subcommands "$subcommands" && return
  2681. case "$cur" in
  2682. -*)
  2683. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2684. ;;
  2685. *)
  2686. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2687. ;;
  2688. esac
  2689. }
  2690. _docker_swarm_init() {
  2691. case "$prev" in
  2692. --advertise-addr)
  2693. if [[ $cur == *: ]] ; then
  2694. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2695. else
  2696. __docker_complete_local_interfaces
  2697. __docker_nospace
  2698. fi
  2699. return
  2700. ;;
  2701. --listen-addr)
  2702. if [[ $cur == *: ]] ; then
  2703. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2704. else
  2705. __docker_complete_local_interfaces --add 0.0.0.0
  2706. __docker_nospace
  2707. fi
  2708. return
  2709. ;;
  2710. esac
  2711. case "$cur" in
  2712. -*)
  2713. COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) )
  2714. ;;
  2715. esac
  2716. }
  2717. _docker_swarm_join() {
  2718. case "$prev" in
  2719. --advertise-addr)
  2720. if [[ $cur == *: ]] ; then
  2721. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2722. else
  2723. __docker_complete_local_interfaces
  2724. __docker_nospace
  2725. fi
  2726. return
  2727. ;;
  2728. --listen-addr)
  2729. if [[ $cur == *: ]] ; then
  2730. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2731. else
  2732. __docker_complete_local_interfaces --add 0.0.0.0
  2733. __docker_nospace
  2734. fi
  2735. return
  2736. ;;
  2737. --availability)
  2738. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2739. return
  2740. ;;
  2741. --token)
  2742. return
  2743. ;;
  2744. esac
  2745. case "$cur" in
  2746. -*)
  2747. COMPREPLY=( $( compgen -W "--advertise-addr --availability --help --listen-addr --token" -- "$cur" ) )
  2748. ;;
  2749. *:)
  2750. COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
  2751. ;;
  2752. esac
  2753. }
  2754. _docker_swarm_join-token() {
  2755. case "$cur" in
  2756. -*)
  2757. COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) )
  2758. ;;
  2759. *)
  2760. local counter=$( __docker_pos_first_nonflag )
  2761. if [ $cword -eq $counter ]; then
  2762. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2763. fi
  2764. ;;
  2765. esac
  2766. }
  2767. _docker_swarm_leave() {
  2768. case "$cur" in
  2769. -*)
  2770. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2771. ;;
  2772. esac
  2773. }
  2774. _docker_swarm_update() {
  2775. case "$prev" in
  2776. --cert-expiry|--dispatcher-heartbeat|--max-snapshots|--snapshot-interval|--task-history-limit)
  2777. return
  2778. ;;
  2779. esac
  2780. case "$cur" in
  2781. -*)
  2782. COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) )
  2783. ;;
  2784. esac
  2785. }
  2786. _docker_node() {
  2787. local subcommands="
  2788. demote
  2789. inspect
  2790. ls list
  2791. promote
  2792. rm remove
  2793. ps
  2794. update
  2795. "
  2796. __docker_subcommands "$subcommands" && return
  2797. case "$cur" in
  2798. -*)
  2799. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2800. ;;
  2801. *)
  2802. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2803. ;;
  2804. esac
  2805. }
  2806. _docker_node_demote() {
  2807. case "$cur" in
  2808. -*)
  2809. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2810. ;;
  2811. *)
  2812. __docker_complete_nodes --filter role=manager
  2813. esac
  2814. }
  2815. _docker_node_inspect() {
  2816. case "$prev" in
  2817. --format|-f)
  2818. return
  2819. ;;
  2820. esac
  2821. case "$cur" in
  2822. -*)
  2823. COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
  2824. ;;
  2825. *)
  2826. __docker_complete_nodes_plus_self
  2827. esac
  2828. }
  2829. _docker_node_list() {
  2830. _docker_node_ls
  2831. }
  2832. _docker_node_ls() {
  2833. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2834. case "$key" in
  2835. id)
  2836. __docker_complete_nodes --cur "${cur##*=}" --id
  2837. return
  2838. ;;
  2839. name)
  2840. __docker_complete_nodes --cur "${cur##*=}" --name
  2841. return
  2842. ;;
  2843. esac
  2844. case "$prev" in
  2845. --filter|-f)
  2846. COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) )
  2847. __docker_nospace
  2848. return
  2849. ;;
  2850. esac
  2851. case "$cur" in
  2852. -*)
  2853. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  2854. ;;
  2855. esac
  2856. }
  2857. _docker_node_promote() {
  2858. case "$cur" in
  2859. -*)
  2860. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2861. ;;
  2862. *)
  2863. __docker_complete_nodes --filter role=worker
  2864. esac
  2865. }
  2866. _docker_node_remove() {
  2867. _docker_node_rm
  2868. }
  2869. _docker_node_rm() {
  2870. case "$cur" in
  2871. -*)
  2872. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2873. ;;
  2874. *)
  2875. __docker_complete_nodes
  2876. esac
  2877. }
  2878. _docker_node_ps() {
  2879. local key=$(__docker_map_key_of_current_option '--filter|-f')
  2880. case "$key" in
  2881. desired-state)
  2882. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  2883. return
  2884. ;;
  2885. name)
  2886. __docker_complete_services --cur "${cur##*=}" --name
  2887. return
  2888. ;;
  2889. esac
  2890. case "$prev" in
  2891. --filter|-f)
  2892. COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) )
  2893. __docker_nospace
  2894. return
  2895. ;;
  2896. esac
  2897. case "$cur" in
  2898. -*)
  2899. COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  2900. ;;
  2901. *)
  2902. __docker_complete_nodes_plus_self
  2903. ;;
  2904. esac
  2905. }
  2906. _docker_node_update() {
  2907. case "$prev" in
  2908. --availability)
  2909. COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) )
  2910. return
  2911. ;;
  2912. --role)
  2913. COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) )
  2914. return
  2915. ;;
  2916. --label-add|--label-rm)
  2917. return
  2918. ;;
  2919. esac
  2920. case "$cur" in
  2921. -*)
  2922. COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) )
  2923. ;;
  2924. *)
  2925. __docker_complete_nodes
  2926. esac
  2927. }
  2928. _docker_pause() {
  2929. _docker_container_pause
  2930. }
  2931. _docker_plugin() {
  2932. local subcommands="
  2933. create
  2934. disable
  2935. enable
  2936. inspect
  2937. install
  2938. ls
  2939. push
  2940. rm
  2941. set
  2942. "
  2943. local aliases="
  2944. list
  2945. remove
  2946. "
  2947. __docker_subcommands "$subcommands $aliases" && return
  2948. case "$cur" in
  2949. -*)
  2950. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  2951. ;;
  2952. *)
  2953. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  2954. ;;
  2955. esac
  2956. }
  2957. _docker_plugin_create() {
  2958. case "$cur" in
  2959. -*)
  2960. COMPREPLY=( $( compgen -W "--compress --help" -- "$cur" ) )
  2961. ;;
  2962. *)
  2963. local counter=$(__docker_pos_first_nonflag)
  2964. if [ $cword -eq $counter ]; then
  2965. # reponame
  2966. return
  2967. elif [ $cword -eq $((counter + 1)) ]; then
  2968. _filedir -d
  2969. fi
  2970. ;;
  2971. esac
  2972. }
  2973. _docker_plugin_disable() {
  2974. case "$cur" in
  2975. -*)
  2976. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  2977. ;;
  2978. *)
  2979. local counter=$(__docker_pos_first_nonflag)
  2980. if [ $cword -eq $counter ]; then
  2981. __docker_complete_plugins_installed
  2982. fi
  2983. ;;
  2984. esac
  2985. }
  2986. _docker_plugin_enable() {
  2987. case "$prev" in
  2988. --timeout)
  2989. return
  2990. ;;
  2991. esac
  2992. case "$cur" in
  2993. -*)
  2994. COMPREPLY=( $( compgen -W "--help --timeout" -- "$cur" ) )
  2995. ;;
  2996. *)
  2997. local counter=$(__docker_pos_first_nonflag '--timeout')
  2998. if [ $cword -eq $counter ]; then
  2999. __docker_complete_plugins_installed
  3000. fi
  3001. ;;
  3002. esac
  3003. }
  3004. _docker_plugin_inspect() {
  3005. case "$prev" in
  3006. --format|f)
  3007. return
  3008. ;;
  3009. esac
  3010. case "$cur" in
  3011. -*)
  3012. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3013. ;;
  3014. *)
  3015. __docker_complete_plugins_installed
  3016. ;;
  3017. esac
  3018. }
  3019. _docker_plugin_install() {
  3020. case "$prev" in
  3021. --alias)
  3022. return
  3023. ;;
  3024. esac
  3025. case "$cur" in
  3026. -*)
  3027. COMPREPLY=( $( compgen -W "--alias --disable --disable-content-trust=false --grant-all-permissions --help" -- "$cur" ) )
  3028. ;;
  3029. esac
  3030. }
  3031. _docker_plugin_list() {
  3032. _docker_plugin_ls
  3033. }
  3034. _docker_plugin_ls() {
  3035. case "$cur" in
  3036. -*)
  3037. COMPREPLY=( $( compgen -W "--help --no-trunc --format --quiet" -- "$cur" ) )
  3038. ;;
  3039. esac
  3040. }
  3041. _docker_plugin_push() {
  3042. case "$cur" in
  3043. -*)
  3044. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3045. ;;
  3046. *)
  3047. local counter=$(__docker_pos_first_nonflag)
  3048. if [ $cword -eq $counter ]; then
  3049. __docker_complete_plugins_installed
  3050. fi
  3051. ;;
  3052. esac
  3053. }
  3054. _docker_plugin_remove() {
  3055. _docker_plugin_rm
  3056. }
  3057. _docker_plugin_rm() {
  3058. case "$cur" in
  3059. -*)
  3060. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3061. ;;
  3062. *)
  3063. __docker_complete_plugins_installed
  3064. ;;
  3065. esac
  3066. }
  3067. _docker_plugin_set() {
  3068. case "$cur" in
  3069. -*)
  3070. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3071. ;;
  3072. *)
  3073. local counter=$(__docker_pos_first_nonflag)
  3074. if [ $cword -eq $counter ]; then
  3075. __docker_complete_plugins_installed
  3076. fi
  3077. ;;
  3078. esac
  3079. }
  3080. _docker_port() {
  3081. _docker_container_port
  3082. }
  3083. _docker_ps() {
  3084. _docker_container_ls
  3085. }
  3086. _docker_pull() {
  3087. _docker_image_pull
  3088. }
  3089. _docker_push() {
  3090. _docker_image_push
  3091. }
  3092. _docker_rename() {
  3093. _docker_container_rename
  3094. }
  3095. _docker_restart() {
  3096. _docker_container_restart
  3097. }
  3098. _docker_rm() {
  3099. _docker_container_rm
  3100. }
  3101. _docker_rmi() {
  3102. _docker_image_rm
  3103. }
  3104. _docker_run() {
  3105. _docker_container_run
  3106. }
  3107. _docker_save() {
  3108. _docker_image_save
  3109. }
  3110. _docker_secret() {
  3111. local subcommands="
  3112. create
  3113. inspect
  3114. ls
  3115. rm
  3116. "
  3117. local aliases="
  3118. list
  3119. remove
  3120. "
  3121. __docker_subcommands "$subcommands $aliases" && return
  3122. case "$cur" in
  3123. -*)
  3124. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3125. ;;
  3126. *)
  3127. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3128. ;;
  3129. esac
  3130. }
  3131. _docker_secret_create() {
  3132. case "$prev" in
  3133. --label|-l)
  3134. return
  3135. ;;
  3136. esac
  3137. case "$cur" in
  3138. -*)
  3139. COMPREPLY=( $( compgen -W "--help --label -l" -- "$cur" ) )
  3140. ;;
  3141. esac
  3142. }
  3143. _docker_secret_inspect() {
  3144. case "$prev" in
  3145. --format|-f)
  3146. return
  3147. ;;
  3148. esac
  3149. case "$cur" in
  3150. -*)
  3151. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3152. ;;
  3153. *)
  3154. __docker_complete_secrets
  3155. ;;
  3156. esac
  3157. }
  3158. _docker_secret_list() {
  3159. _docker_secret_ls
  3160. }
  3161. _docker_secret_ls() {
  3162. case "$cur" in
  3163. -*)
  3164. COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) )
  3165. ;;
  3166. esac
  3167. }
  3168. _docker_secret_remove() {
  3169. case "$cur" in
  3170. -*)
  3171. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3172. ;;
  3173. *)
  3174. __docker_complete_secrets
  3175. ;;
  3176. esac
  3177. }
  3178. _docker_secret_rm() {
  3179. _docker_secret_remove
  3180. }
  3181. _docker_search() {
  3182. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3183. case "$key" in
  3184. is-automated)
  3185. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3186. return
  3187. ;;
  3188. is-official)
  3189. COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
  3190. return
  3191. ;;
  3192. esac
  3193. case "$prev" in
  3194. --filter|-f)
  3195. COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) )
  3196. __docker_nospace
  3197. return
  3198. ;;
  3199. --limit)
  3200. return
  3201. ;;
  3202. esac
  3203. case "$cur" in
  3204. -*)
  3205. COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) )
  3206. ;;
  3207. esac
  3208. }
  3209. _docker_stack() {
  3210. local subcommands="
  3211. deploy
  3212. ls
  3213. ps
  3214. rm
  3215. services
  3216. "
  3217. local aliases="
  3218. down
  3219. list
  3220. remove
  3221. up
  3222. "
  3223. __docker_subcommands "$subcommands $aliases" && return
  3224. case "$cur" in
  3225. -*)
  3226. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3227. ;;
  3228. *)
  3229. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3230. ;;
  3231. esac
  3232. }
  3233. _docker_stack_deploy() {
  3234. case "$prev" in
  3235. --bundle-file)
  3236. if __docker_is_experimental ; then
  3237. _filedir dab
  3238. return
  3239. fi
  3240. ;;
  3241. --compose-file|-c)
  3242. _filedir yml
  3243. return
  3244. ;;
  3245. esac
  3246. case "$cur" in
  3247. -*)
  3248. local options="--compose-file -c --help --with-registry-auth"
  3249. __docker_is_experimental && options+=" --bundle-file"
  3250. COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
  3251. ;;
  3252. esac
  3253. }
  3254. _docker_stack_down() {
  3255. _docker_stack_rm
  3256. }
  3257. _docker_stack_list() {
  3258. _docker_stack_ls
  3259. }
  3260. _docker_stack_ls() {
  3261. case "$cur" in
  3262. -*)
  3263. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3264. ;;
  3265. esac
  3266. }
  3267. _docker_stack_ps() {
  3268. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3269. case "$key" in
  3270. desired-state)
  3271. COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) )
  3272. return
  3273. ;;
  3274. id)
  3275. __docker_complete_stacks --cur "${cur##*=}" --id
  3276. return
  3277. ;;
  3278. name)
  3279. __docker_complete_stacks --cur "${cur##*=}" --name
  3280. return
  3281. ;;
  3282. esac
  3283. case "$prev" in
  3284. --filter|-f)
  3285. COMPREPLY=( $( compgen -S = -W "id name desired-state" -- "$cur" ) )
  3286. __docker_nospace
  3287. return
  3288. ;;
  3289. esac
  3290. case "$cur" in
  3291. -*)
  3292. COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) )
  3293. ;;
  3294. *)
  3295. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  3296. if [ $cword -eq $counter ]; then
  3297. __docker_complete_stacks
  3298. fi
  3299. ;;
  3300. esac
  3301. }
  3302. _docker_stack_remove() {
  3303. _docker_stack_rm
  3304. }
  3305. _docker_stack_rm() {
  3306. case "$cur" in
  3307. -*)
  3308. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3309. ;;
  3310. *)
  3311. local counter=$(__docker_pos_first_nonflag)
  3312. if [ $cword -eq $counter ]; then
  3313. __docker_complete_stacks
  3314. fi
  3315. ;;
  3316. esac
  3317. }
  3318. _docker_stack_services() {
  3319. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3320. case "$key" in
  3321. id)
  3322. __docker_complete_services --cur "${cur##*=}" --id
  3323. return
  3324. ;;
  3325. label)
  3326. return
  3327. ;;
  3328. name)
  3329. __docker_complete_services --cur "${cur##*=}" --name
  3330. return
  3331. ;;
  3332. esac
  3333. case "$prev" in
  3334. --filter|-f)
  3335. COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
  3336. __docker_nospace
  3337. return
  3338. ;;
  3339. esac
  3340. case "$cur" in
  3341. -*)
  3342. COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) )
  3343. ;;
  3344. *)
  3345. local counter=$(__docker_pos_first_nonflag '--filter|-f')
  3346. if [ $cword -eq $counter ]; then
  3347. __docker_complete_stacks
  3348. fi
  3349. ;;
  3350. esac
  3351. }
  3352. _docker_stack_up() {
  3353. _docker_stack_deploy
  3354. }
  3355. _docker_start() {
  3356. _docker_container_start
  3357. }
  3358. _docker_stats() {
  3359. _docker_container_stats
  3360. }
  3361. _docker_stop() {
  3362. _docker_container_stop
  3363. }
  3364. _docker_system() {
  3365. local subcommands="
  3366. df
  3367. events
  3368. info
  3369. prune
  3370. "
  3371. __docker_subcommands "$subcommands $aliases" && return
  3372. case "$cur" in
  3373. -*)
  3374. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3375. ;;
  3376. *)
  3377. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3378. ;;
  3379. esac
  3380. }
  3381. _docker_system_df() {
  3382. case "$cur" in
  3383. -*)
  3384. COMPREPLY=( $( compgen -W "--help --verbose -v" -- "$cur" ) )
  3385. ;;
  3386. esac
  3387. }
  3388. _docker_system_events() {
  3389. local key=$(__docker_map_key_of_current_option '-f|--filter')
  3390. case "$key" in
  3391. container)
  3392. __docker_complete_containers_all --cur "${cur##*=}"
  3393. return
  3394. ;;
  3395. daemon)
  3396. local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p')
  3397. COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) )
  3398. return
  3399. ;;
  3400. event)
  3401. COMPREPLY=( $( compgen -W "
  3402. attach
  3403. commit
  3404. connect
  3405. copy
  3406. create
  3407. delete
  3408. destroy
  3409. detach
  3410. die
  3411. disconnect
  3412. exec_create
  3413. exec_detach
  3414. exec_start
  3415. export
  3416. health_status
  3417. import
  3418. kill
  3419. load
  3420. mount
  3421. oom
  3422. pause
  3423. pull
  3424. push
  3425. reload
  3426. rename
  3427. resize
  3428. restart
  3429. save
  3430. start
  3431. stop
  3432. tag
  3433. top
  3434. unmount
  3435. unpause
  3436. untag
  3437. update
  3438. " -- "${cur##*=}" ) )
  3439. return
  3440. ;;
  3441. image)
  3442. cur="${cur##*=}"
  3443. __docker_complete_images
  3444. return
  3445. ;;
  3446. network)
  3447. __docker_complete_networks --cur "${cur##*=}"
  3448. return
  3449. ;;
  3450. type)
  3451. COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) )
  3452. return
  3453. ;;
  3454. volume)
  3455. __docker_complete_volumes --cur "${cur##*=}"
  3456. return
  3457. ;;
  3458. esac
  3459. case "$prev" in
  3460. --filter|-f)
  3461. COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) )
  3462. __docker_nospace
  3463. return
  3464. ;;
  3465. --since|--until)
  3466. return
  3467. ;;
  3468. esac
  3469. case "$cur" in
  3470. -*)
  3471. COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) )
  3472. ;;
  3473. esac
  3474. }
  3475. _docker_system_info() {
  3476. case "$prev" in
  3477. --format|-f)
  3478. return
  3479. ;;
  3480. esac
  3481. case "$cur" in
  3482. -*)
  3483. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3484. ;;
  3485. esac
  3486. }
  3487. _docker_system_prune() {
  3488. case "$prev" in
  3489. --filter)
  3490. COMPREPLY=( $( compgen -W "until" -S = -- "$cur" ) )
  3491. __docker_nospace
  3492. return
  3493. ;;
  3494. esac
  3495. case "$cur" in
  3496. -*)
  3497. COMPREPLY=( $( compgen -W "--all -a --force -f --filter --help" -- "$cur" ) )
  3498. ;;
  3499. esac
  3500. }
  3501. _docker_tag() {
  3502. _docker_image_tag
  3503. }
  3504. _docker_unpause() {
  3505. _docker_container_unpause
  3506. }
  3507. _docker_update() {
  3508. _docker_container_update
  3509. }
  3510. _docker_top() {
  3511. _docker_container_top
  3512. }
  3513. _docker_version() {
  3514. case "$prev" in
  3515. --format|-f)
  3516. return
  3517. ;;
  3518. esac
  3519. case "$cur" in
  3520. -*)
  3521. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3522. ;;
  3523. esac
  3524. }
  3525. _docker_volume_create() {
  3526. case "$prev" in
  3527. --driver|-d)
  3528. __docker_complete_plugins_bundled --type Volume
  3529. return
  3530. ;;
  3531. --label|--opt|-o)
  3532. return
  3533. ;;
  3534. esac
  3535. case "$cur" in
  3536. -*)
  3537. COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) )
  3538. ;;
  3539. esac
  3540. }
  3541. _docker_volume_inspect() {
  3542. case "$prev" in
  3543. --format|-f)
  3544. return
  3545. ;;
  3546. esac
  3547. case "$cur" in
  3548. -*)
  3549. COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
  3550. ;;
  3551. *)
  3552. __docker_complete_volumes
  3553. ;;
  3554. esac
  3555. }
  3556. _docker_volume_ls() {
  3557. local key=$(__docker_map_key_of_current_option '--filter|-f')
  3558. case "$key" in
  3559. dangling)
  3560. COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) )
  3561. return
  3562. ;;
  3563. driver)
  3564. __docker_complete_plugins_bundled --cur "${cur##*=}" --type Volume
  3565. return
  3566. ;;
  3567. name)
  3568. __docker_complete_volumes --cur "${cur##*=}"
  3569. return
  3570. ;;
  3571. esac
  3572. case "$prev" in
  3573. --filter|-f)
  3574. COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) )
  3575. __docker_nospace
  3576. return
  3577. ;;
  3578. --format)
  3579. return
  3580. ;;
  3581. esac
  3582. case "$cur" in
  3583. -*)
  3584. COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
  3585. ;;
  3586. esac
  3587. }
  3588. _docker_volume_prune() {
  3589. case "$cur" in
  3590. -*)
  3591. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3592. ;;
  3593. esac
  3594. }
  3595. _docker_volume_rm() {
  3596. case "$cur" in
  3597. -*)
  3598. COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) )
  3599. ;;
  3600. *)
  3601. __docker_complete_volumes
  3602. ;;
  3603. esac
  3604. }
  3605. _docker_volume() {
  3606. local subcommands="
  3607. create
  3608. inspect
  3609. ls
  3610. prune
  3611. rm
  3612. "
  3613. __docker_subcommands "$subcommands" && return
  3614. case "$cur" in
  3615. -*)
  3616. COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
  3617. ;;
  3618. *)
  3619. COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
  3620. ;;
  3621. esac
  3622. }
  3623. _docker_wait() {
  3624. _docker_container_wait
  3625. }
  3626. _docker() {
  3627. local previous_extglob_setting=$(shopt -p extglob)
  3628. shopt -s extglob
  3629. local management_commands=(
  3630. container
  3631. image
  3632. network
  3633. node
  3634. plugin
  3635. secret
  3636. service
  3637. stack
  3638. system
  3639. volume
  3640. )
  3641. local top_level_commands=(
  3642. build
  3643. login
  3644. logout
  3645. run
  3646. search
  3647. version
  3648. )
  3649. local legacy_commands=(
  3650. commit
  3651. cp
  3652. create
  3653. diff
  3654. events
  3655. exec
  3656. export
  3657. history
  3658. images
  3659. import
  3660. info
  3661. inspect
  3662. kill
  3663. load
  3664. logs
  3665. pause
  3666. port
  3667. ps
  3668. pull
  3669. push
  3670. rename
  3671. restart
  3672. rm
  3673. rmi
  3674. save
  3675. start
  3676. stats
  3677. stop
  3678. swarm
  3679. tag
  3680. top
  3681. unpause
  3682. update
  3683. wait
  3684. )
  3685. local experimental_commands=(
  3686. deploy
  3687. )
  3688. local commands=(${management_commands[*]} ${top_level_commands[*]})
  3689. [ -z "$DOCKER_HIDE_LEGACY_COMMANDS" ] && commands+=(${legacy_commands[*]})
  3690. # These options are valid as global options for all client commands
  3691. # and valid as command options for `docker daemon`
  3692. local global_boolean_options="
  3693. --debug -D
  3694. --tls
  3695. --tlsverify
  3696. "
  3697. local global_options_with_args="
  3698. --config
  3699. --host -H
  3700. --log-level -l
  3701. --tlscacert
  3702. --tlscert
  3703. --tlskey
  3704. "
  3705. local host config
  3706. COMPREPLY=()
  3707. local cur prev words cword
  3708. _get_comp_words_by_ref -n : cur prev words cword
  3709. local command='docker' command_pos=0 subcommand_pos
  3710. local counter=1
  3711. while [ $counter -lt $cword ]; do
  3712. case "${words[$counter]}" in
  3713. # save host so that completion can use custom daemon
  3714. --host|-H)
  3715. (( counter++ ))
  3716. host="${words[$counter]}"
  3717. ;;
  3718. # save config so that completion can use custom configuration directories
  3719. --config)
  3720. (( counter++ ))
  3721. config="${words[$counter]}"
  3722. ;;
  3723. $(__docker_to_extglob "$global_options_with_args") )
  3724. (( counter++ ))
  3725. ;;
  3726. -*)
  3727. ;;
  3728. =)
  3729. (( counter++ ))
  3730. ;;
  3731. *)
  3732. command="${words[$counter]}"
  3733. command_pos=$counter
  3734. break
  3735. ;;
  3736. esac
  3737. (( counter++ ))
  3738. done
  3739. local binary="${words[0]}"
  3740. if [[ $binary == ?(*/)dockerd ]] ; then
  3741. # for the dockerd binary, we reuse completion of `docker daemon`.
  3742. # dockerd does not have subcommands and global options.
  3743. command=daemon
  3744. command_pos=0
  3745. fi
  3746. local completions_func=_docker_${command}
  3747. declare -F $completions_func >/dev/null && $completions_func
  3748. eval "$previous_extglob_setting"
  3749. return 0
  3750. }
  3751. eval "$__docker_previous_extglob_setting"
  3752. unset __docker_previous_extglob_setting
  3753. complete -F _docker docker dockerd