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