docker 80 KB

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