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