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