docker 80 KB

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