docker 83 KB

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