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