docker 79 KB

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