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