docker 81 KB

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