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