docker 76 KB

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