github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/contrib/completion/bash/docker (about) 1 #!/bin/bash 2 # 3 # bash completion file for core docker commands 4 # 5 # This script provides completion of: 6 # - commands and their options 7 # - container ids and names 8 # - image repos and tags 9 # - filepaths 10 # 11 # To enable the completions either: 12 # - place this file in /etc/bash_completion.d 13 # or 14 # - copy this file to e.g. ~/.docker-completion.sh and add the line 15 # below to your .bashrc after bash completion features are loaded 16 # . ~/.docker-completion.sh 17 # 18 # Configuration: 19 # 20 # For several commands, the amount of completions can be configured by 21 # setting environment variables. 22 # 23 # DOCKER_COMPLETION_SHOW_CONTAINER_IDS 24 # DOCKER_COMPLETION_SHOW_NETWORK_IDS 25 # DOCKER_COMPLETION_SHOW_NODE_IDS 26 # DOCKER_COMPLETION_SHOW_SERVICE_IDS 27 # "no" - Show names only (default) 28 # "yes" - Show names and ids 29 # 30 # You can tailor completion for the "events", "history", "inspect", "run", 31 # "rmi" and "save" commands by settings the following environment 32 # variables: 33 # 34 # DOCKER_COMPLETION_SHOW_IMAGE_IDS 35 # "none" - Show names only (default) 36 # "non-intermediate" - Show names and ids, but omit intermediate image IDs 37 # "all" - Show names and ids, including intermediate image IDs 38 # 39 # DOCKER_COMPLETION_SHOW_TAGS 40 # "yes" - include tags in completion options (default) 41 # "no" - don't include tags in completion options 42 43 # 44 # Note: 45 # Currently, the completions will not work if the docker daemon is not 46 # bound to the default communication port/socket 47 # If the docker daemon is using a unix socket for communication your user 48 # must have access to the socket for the completions to function correctly 49 # 50 # Note for developers: 51 # Please arrange options sorted alphabetically by long name with the short 52 # options immediately following their corresponding long form. 53 # This order should be applied to lists, alternatives and code blocks. 54 55 __docker_previous_extglob_setting=$(shopt -p extglob) 56 shopt -s extglob 57 58 __docker_q() { 59 docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@" 60 } 61 62 # __docker_containers returns a list of containers. Additional options to 63 # `docker ps` may be specified in order to filter the list, e.g. 64 # `__docker_containers --filter status=running` 65 # By default, only names are returned. 66 # Set DOCKER_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs. 67 # An optional first option `--id|--name` may be used to limit the 68 # output to the IDs or names of matching items. This setting takes 69 # precedence over the environment setting. 70 __docker_containers() { 71 local format 72 if [ "$1" = "--id" ] ; then 73 format='{{.ID}}' 74 shift 75 elif [ "$1" = "--name" ] ; then 76 format='{{.Names}}' 77 shift 78 elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS}" = yes ] ; then 79 format='{{.ID}} {{.Names}}' 80 else 81 format='{{.Names}}' 82 fi 83 __docker_q ps --format "$format" "$@" 84 } 85 86 # __docker_complete_containers applies completion of containers based on the current 87 # value of `$cur` or the value of the optional first option `--cur`, if given. 88 # Additional filters may be appended, see `__docker_containers`. 89 __docker_complete_containers() { 90 local current="$cur" 91 if [ "$1" = "--cur" ] ; then 92 current="$2" 93 shift 2 94 fi 95 COMPREPLY=( $(compgen -W "$(__docker_containers "$@")" -- "$current") ) 96 } 97 98 __docker_complete_containers_all() { 99 __docker_complete_containers "$@" --all 100 } 101 102 __docker_complete_containers_running() { 103 __docker_complete_containers "$@" --filter status=running 104 } 105 106 __docker_complete_containers_stopped() { 107 __docker_complete_containers "$@" --filter status=exited 108 } 109 110 __docker_complete_containers_unpauseable() { 111 __docker_complete_containers "$@" --filter status=paused 112 } 113 114 __docker_complete_container_names() { 115 local containers=( $(__docker_q ps -aq --no-trunc) ) 116 local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") ) 117 names=( "${names[@]#/}" ) # trim off the leading "/" from the container names 118 COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") ) 119 } 120 121 __docker_complete_container_ids() { 122 local containers=( $(__docker_q ps -aq) ) 123 COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") ) 124 } 125 126 __docker_complete_images() { 127 local images_args="" 128 129 case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in 130 all) 131 images_args="--no-trunc -a" 132 ;; 133 non-intermediate) 134 images_args="--no-trunc" 135 ;; 136 esac 137 138 local repo_print_command 139 if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then 140 repo_print_command='print $1; print $1":"$2' 141 else 142 repo_print_command='print $1' 143 fi 144 145 local awk_script 146 case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in 147 all|non-intermediate) 148 awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }' 149 ;; 150 none|*) 151 awk_script='NR>1 && $1 != "<none>" { '"$repo_print_command"' }' 152 ;; 153 esac 154 155 local images=$(__docker_q images $images_args | awk "$awk_script") 156 COMPREPLY=( $(compgen -W "$images" -- "$cur") ) 157 __ltrim_colon_completions "$cur" 158 } 159 160 __docker_complete_image_repos() { 161 local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')" 162 COMPREPLY=( $(compgen -W "$repos" -- "$cur") ) 163 } 164 165 __docker_complete_image_repos_and_tags() { 166 local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')" 167 COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") ) 168 __ltrim_colon_completions "$cur" 169 } 170 171 __docker_complete_containers_and_images() { 172 __docker_complete_containers_all 173 local containers=( "${COMPREPLY[@]}" ) 174 __docker_complete_images 175 COMPREPLY+=( "${containers[@]}" ) 176 } 177 178 # __docker_networks returns a list of all networks. Additional options to 179 # `docker network ls` may be specified in order to filter the list, e.g. 180 # `__docker_networks --filter type=custom` 181 # By default, only names are returned. 182 # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete IDs. 183 # An optional first option `--id|--name` may be used to limit the 184 # output to the IDs or names of matching items. This setting takes 185 # precedence over the environment setting. 186 __docker_networks() { 187 local format 188 if [ "$1" = "--id" ] ; then 189 format='{{.ID}}' 190 shift 191 elif [ "$1" = "--name" ] ; then 192 format='{{.Name}}' 193 shift 194 elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] ; then 195 format='{{.ID}} {{.Name}}' 196 else 197 format='{{.Name}}' 198 fi 199 __docker_q network ls --format "$format" "$@" 200 } 201 202 # __docker_complete_networks applies completion of networks based on the current 203 # value of `$cur` or the value of the optional first option `--cur`, if given. 204 # Additional filters may be appended, see `__docker_networks`. 205 __docker_complete_networks() { 206 local current="$cur" 207 if [ "$1" = "--cur" ] ; then 208 current="$2" 209 shift 2 210 fi 211 COMPREPLY=( $(compgen -W "$(__docker_networks "$@")" -- "$current") ) 212 } 213 214 __docker_complete_containers_in_network() { 215 local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1") 216 COMPREPLY=( $(compgen -W "$containers" -- "$cur") ) 217 } 218 219 # __docker_volumes returns a list of all volumes. Additional options to 220 # `docker volume ls` may be specified in order to filter the list, e.g. 221 # `__docker_volumes --filter dangling=true` 222 # Because volumes do not have IDs, this function does not distinguish between 223 # IDs and names. 224 __docker_volumes() { 225 __docker_q volume ls -q "$@" 226 } 227 228 # __docker_complete_volumes applies completion of volumes based on the current 229 # value of `$cur` or the value of the optional first option `--cur`, if given. 230 # Additional filters may be appended, see `__docker_volumes`. 231 __docker_complete_volumes() { 232 local current="$cur" 233 if [ "$1" = "--cur" ] ; then 234 current="$2" 235 shift 2 236 fi 237 COMPREPLY=( $(compgen -W "$(__docker_volumes "$@")" -- "$current") ) 238 } 239 240 # __docker_plugins returns a list of all plugins of a given type. 241 # The type has to be specified with the mandatory option `--type`. 242 # Valid types are: Network, Volume, Authorization. 243 # Completions may be added or removed with `--add` and `--remove` 244 __docker_plugins() { 245 local type add=() remove=() 246 while true ; do 247 case "$1" in 248 --type) 249 type="$2" 250 shift 2 251 ;; 252 --add) 253 add+=("$2") 254 shift 2 255 ;; 256 --remove) 257 remove+=("$2") 258 shift 2 259 ;; 260 *) 261 break 262 ;; 263 esac 264 done 265 266 local plugins=($(__docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $type: //p")) 267 for del in "${remove[@]}" ; do 268 plugins=(${plugins[@]/$del/}) 269 done 270 echo "${plugins[@]} ${add[@]}" 271 } 272 273 # __docker_complete_plugins applies completion of plugins based on the current 274 # value of `$cur` or the value of the optional first option `--cur`, if given. 275 # The plugin type has to be specified with the next option `--type`. 276 __docker_complete_plugins() { 277 local current="$cur" 278 if [ "$1" = "--cur" ] ; then 279 current="$2" 280 shift 2 281 fi 282 COMPREPLY=( $(compgen -W "$(__docker_plugins "$@")" -- "$current") ) 283 } 284 285 __docker_runtimes() { 286 __docker_q info | sed -n 's/^Runtimes: \(.*\)/\1/p' 287 } 288 289 __docker_complete_runtimes() { 290 COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") ) 291 } 292 293 # __docker_nodes returns a list of all nodes. Additional options to 294 # `docker node ls` may be specified in order to filter the list, e.g. 295 # `__docker_nodes --filter role=manager` 296 # By default, only node names are returned. 297 # Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs. 298 # An optional first option `--id|--name` may be used to limit the 299 # output to the IDs or names of matching items. This setting takes 300 # precedence over the environment setting. 301 __docker_nodes() { 302 local fields='$2' # default: node name only 303 [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name 304 305 if [ "$1" = "--id" ] ; then 306 fields='$1' # IDs only 307 shift 308 elif [ "$1" = "--name" ] ; then 309 fields='$2' # names only 310 shift 311 fi 312 __docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}" 313 } 314 315 # __docker_complete_nodes applies completion of nodes based on the current 316 # value of `$cur` or the value of the optional first option `--cur`, if given. 317 # Additional filters may be appended, see `__docker_nodes`. 318 __docker_complete_nodes() { 319 local current="$cur" 320 if [ "$1" = "--cur" ] ; then 321 current="$2" 322 shift 2 323 fi 324 COMPREPLY=( $(compgen -W "$(__docker_nodes "$@")" -- "$current") ) 325 } 326 327 __docker_complete_nodes_plus_self() { 328 __docker_complete_nodes "$@" 329 COMPREPLY+=( self ) 330 } 331 332 # __docker_services returns a list of all services. Additional options to 333 # `docker service ls` may be specified in order to filter the list, e.g. 334 # `__docker_services --filter name=xxx` 335 # By default, only node names are returned. 336 # Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete IDs. 337 # An optional first option `--id|--name` may be used to limit the 338 # output to the IDs or names of matching items. This setting takes 339 # precedence over the environment setting. 340 __docker_services() { 341 local fields='$2' # default: service name only 342 [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name 343 344 if [ "$1" = "--id" ] ; then 345 fields='$1' # IDs only 346 shift 347 elif [ "$1" = "--name" ] ; then 348 fields='$2' # names only 349 shift 350 fi 351 __docker_q service ls "$@" | awk "NR>1 {print $fields}" 352 } 353 354 # __docker_complete_services applies completion of services based on the current 355 # value of `$cur` or the value of the optional first option `--cur`, if given. 356 # Additional filters may be appended, see `__docker_services`. 357 __docker_complete_services() { 358 local current="$cur" 359 if [ "$1" = "--cur" ] ; then 360 current="$2" 361 shift 2 362 fi 363 COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") ) 364 } 365 366 # __docker_append_to_completions appends the word passed as an argument to every 367 # word in `$COMPREPLY`. 368 # Normally you do this with `compgen -S` while generating the completions. 369 # This function allows you to append a suffix later. It allows you to use 370 # the __docker_complete_XXX functions in cases where you need a suffix. 371 __docker_append_to_completions() { 372 COMPREPLY=( ${COMPREPLY[@]/%/"$1"} ) 373 } 374 375 # __docker_pos_first_nonflag finds the position of the first word that is neither 376 # option nor an option's argument. If there are options that require arguments, 377 # you should pass a glob describing those options, e.g. "--option1|-o|--option2" 378 # Use this function to restrict completions to exact positions after the argument list. 379 __docker_pos_first_nonflag() { 380 local argument_flags=$1 381 382 local counter=$((${subcommand_pos:-${command_pos}} + 1)) 383 while [ $counter -le $cword ]; do 384 if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then 385 (( counter++ )) 386 # eat "=" in case of --option=arg syntax 387 [ "${words[$counter]}" = "=" ] && (( counter++ )) 388 else 389 case "${words[$counter]}" in 390 -*) 391 ;; 392 *) 393 break 394 ;; 395 esac 396 fi 397 398 # Bash splits words at "=", retaining "=" as a word, examples: 399 # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words 400 while [ "${words[$counter + 1]}" = "=" ] ; do 401 counter=$(( counter + 2)) 402 done 403 404 (( counter++ )) 405 done 406 407 echo $counter 408 } 409 410 # __docker_map_key_of_current_option returns `key` if we are currently completing the 411 # value of a map option (`key=value`) which matches the extglob given as an argument. 412 # This function is needed for key-specific completions. 413 __docker_map_key_of_current_option() { 414 local glob="$1" 415 416 local key glob_pos 417 if [ "$cur" = "=" ] ; then # key= case 418 key="$prev" 419 glob_pos=$((cword - 2)) 420 elif [[ $cur == *=* ]] ; then # key=value case (OSX) 421 key=${cur%=*} 422 glob_pos=$((cword - 1)) 423 elif [ "$prev" = "=" ] ; then 424 key=${words[$cword - 2]} # key=value case 425 glob_pos=$((cword - 3)) 426 else 427 return 428 fi 429 430 [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax 431 432 [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key" 433 } 434 435 # __docker_value_of_option returns the value of the first option matching `option_glob`. 436 # Valid values for `option_glob` are option names like `--log-level` and globs like 437 # `--log-level|-l` 438 # Only positions between the command and the current word are considered. 439 __docker_value_of_option() { 440 local option_extglob=$(__docker_to_extglob "$1") 441 442 local counter=$((command_pos + 1)) 443 while [ $counter -lt $cword ]; do 444 case ${words[$counter]} in 445 $option_extglob ) 446 echo ${words[$counter + 1]} 447 break 448 ;; 449 esac 450 (( counter++ )) 451 done 452 } 453 454 # __docker_to_alternatives transforms a multiline list of strings into a single line 455 # string with the words separated by `|`. 456 # This is used to prepare arguments to __docker_pos_first_nonflag(). 457 __docker_to_alternatives() { 458 local parts=( $1 ) 459 local IFS='|' 460 echo "${parts[*]}" 461 } 462 463 # __docker_to_extglob transforms a multiline list of options into an extglob pattern 464 # suitable for use in case statements. 465 __docker_to_extglob() { 466 local extglob=$( __docker_to_alternatives "$1" ) 467 echo "@($extglob)" 468 } 469 470 # __docker_subcommands processes subcommands 471 # Locates the first occurrence of any of the subcommands contained in the 472 # first argument. In case of a match, calls the corresponding completion 473 # function and returns 0. 474 # If no match is found, 1 is returned. The calling function can then 475 # continue processing its completion. 476 # 477 # TODO if the preceding command has options that accept arguments and an 478 # argument is equal ot one of the subcommands, this is falsely detected as 479 # a match. 480 __docker_subcommands() { 481 local subcommands="$1" 482 483 local counter=$(($command_pos + 1)) 484 while [ $counter -lt $cword ]; do 485 case "${words[$counter]}" in 486 $(__docker_to_extglob "$subcommands") ) 487 subcommand_pos=$counter 488 local subcommand=${words[$counter]} 489 local completions_func=_docker_${command}_${subcommand} 490 declare -F $completions_func >/dev/null && $completions_func 491 return 0 492 ;; 493 esac 494 (( counter++ )) 495 done 496 return 1 497 } 498 499 # __docker_nospace suppresses trailing whitespace 500 __docker_nospace() { 501 # compopt is not available in ancient bash versions 502 type compopt &>/dev/null && compopt -o nospace 503 } 504 505 __docker_complete_resolved_hostname() { 506 command -v host >/dev/null 2>&1 || return 507 COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') ) 508 } 509 510 __docker_local_interfaces() { 511 command -v ip >/dev/null 2>&1 || return 512 ip addr show scope global 2>/dev/null | sed -n 's| \+inet \([0-9.]\+\).* \([^ ]\+\)|\1 \2|p' 513 } 514 515 __docker_complete_local_interfaces() { 516 local additional_interface 517 if [ "$1" = "--add" ] ; then 518 additional_interface="$2" 519 fi 520 521 COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) ) 522 } 523 524 __docker_complete_capabilities() { 525 # The list of capabilities is defined in types.go, ALL was added manually. 526 COMPREPLY=( $( compgen -W " 527 ALL 528 AUDIT_CONTROL 529 AUDIT_WRITE 530 AUDIT_READ 531 BLOCK_SUSPEND 532 CHOWN 533 DAC_OVERRIDE 534 DAC_READ_SEARCH 535 FOWNER 536 FSETID 537 IPC_LOCK 538 IPC_OWNER 539 KILL 540 LEASE 541 LINUX_IMMUTABLE 542 MAC_ADMIN 543 MAC_OVERRIDE 544 MKNOD 545 NET_ADMIN 546 NET_BIND_SERVICE 547 NET_BROADCAST 548 NET_RAW 549 SETFCAP 550 SETGID 551 SETPCAP 552 SETUID 553 SYS_ADMIN 554 SYS_BOOT 555 SYS_CHROOT 556 SYSLOG 557 SYS_MODULE 558 SYS_NICE 559 SYS_PACCT 560 SYS_PTRACE 561 SYS_RAWIO 562 SYS_RESOURCE 563 SYS_TIME 564 SYS_TTY_CONFIG 565 WAKE_ALARM 566 " -- "$cur" ) ) 567 } 568 569 __docker_complete_detach-keys() { 570 case "$prev" in 571 --detach-keys) 572 case "$cur" in 573 *,) 574 COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) ) 575 ;; 576 *) 577 COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) ) 578 ;; 579 esac 580 581 __docker_nospace 582 return 583 ;; 584 esac 585 return 1 586 } 587 588 __docker_complete_isolation() { 589 COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) ) 590 } 591 592 __docker_complete_log_drivers() { 593 COMPREPLY=( $( compgen -W " 594 awslogs 595 etwlogs 596 fluentd 597 gcplogs 598 gelf 599 journald 600 json-file 601 logentries 602 none 603 splunk 604 syslog 605 " -- "$cur" ) ) 606 } 607 608 __docker_complete_log_options() { 609 # see docs/reference/logging/index.md 610 local awslogs_options="awslogs-region awslogs-group awslogs-stream" 611 local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag" 612 local gcplogs_options="env gcp-log-cmd gcp-project labels" 613 local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag" 614 local journald_options="env labels tag" 615 local json_file_options="env labels max-file max-size" 616 local logentries_options="logentries-token" 617 local syslog_options="env labels syslog-address syslog-facility syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify tag" 618 local splunk_options="env labels 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" 619 620 local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $logentries_options $json_file_options $syslog_options $splunk_options" 621 622 case $(__docker_value_of_option --log-driver) in 623 '') 624 COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) ) 625 ;; 626 awslogs) 627 COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) ) 628 ;; 629 fluentd) 630 COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) ) 631 ;; 632 gcplogs) 633 COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) ) 634 ;; 635 gelf) 636 COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) ) 637 ;; 638 journald) 639 COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) ) 640 ;; 641 json-file) 642 COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) ) 643 ;; 644 logentries) 645 COMPREPLY=( $( compgen -W "$logentries_options" -S = -- "$cur" ) ) 646 ;; 647 syslog) 648 COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) ) 649 ;; 650 splunk) 651 COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) ) 652 ;; 653 *) 654 return 655 ;; 656 esac 657 658 __docker_nospace 659 } 660 661 __docker_complete_log_driver_options() { 662 local key=$(__docker_map_key_of_current_option '--log-opt') 663 case "$key" in 664 fluentd-async-connect) 665 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 666 return 667 ;; 668 gelf-address) 669 COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) ) 670 __docker_nospace 671 return 672 ;; 673 gelf-compression-level) 674 COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) ) 675 return 676 ;; 677 gelf-compression-type) 678 COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) ) 679 return 680 ;; 681 syslog-address) 682 COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) ) 683 __docker_nospace 684 __ltrim_colon_completions "${cur}" 685 return 686 ;; 687 syslog-facility) 688 COMPREPLY=( $( compgen -W " 689 auth 690 authpriv 691 cron 692 daemon 693 ftp 694 kern 695 local0 696 local1 697 local2 698 local3 699 local4 700 local5 701 local6 702 local7 703 lpr 704 mail 705 news 706 syslog 707 user 708 uucp 709 " -- "${cur##*=}" ) ) 710 return 711 ;; 712 syslog-format) 713 COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) ) 714 return 715 ;; 716 syslog-tls-ca-cert|syslog-tls-cert|syslog-tls-key) 717 _filedir 718 return 719 ;; 720 syslog-tls-skip-verify) 721 COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) ) 722 return 723 ;; 724 splunk-url) 725 COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) ) 726 __docker_nospace 727 __ltrim_colon_completions "${cur}" 728 return 729 ;; 730 splunk-gzip|splunk-insecureskipverify|splunk-verify-connection) 731 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 732 return 733 ;; 734 splunk-format) 735 COMPREPLY=( $( compgen -W "inline json raw" -- "${cur##*=}" ) ) 736 return 737 ;; 738 esac 739 return 1 740 } 741 742 __docker_complete_log_levels() { 743 COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) 744 } 745 746 __docker_complete_restart() { 747 case "$prev" in 748 --restart) 749 case "$cur" in 750 on-failure:*) 751 ;; 752 *) 753 COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") ) 754 ;; 755 esac 756 return 757 ;; 758 esac 759 return 1 760 } 761 762 # __docker_complete_signals returns a subset of the available signals that is most likely 763 # relevant in the context of docker containers 764 __docker_complete_signals() { 765 local signals=( 766 SIGCONT 767 SIGHUP 768 SIGINT 769 SIGKILL 770 SIGQUIT 771 SIGSTOP 772 SIGTERM 773 SIGUSR1 774 SIGUSR2 775 ) 776 COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) ) 777 } 778 779 __docker_complete_user_group() { 780 if [[ $cur == *:* ]] ; then 781 COMPREPLY=( $(compgen -g -- "${cur#*:}") ) 782 else 783 COMPREPLY=( $(compgen -u -S : -- "$cur") ) 784 __docker_nospace 785 fi 786 } 787 788 _docker_docker() { 789 # global options that may appear after the docker command 790 local boolean_options=" 791 $global_boolean_options 792 --help 793 --version -v 794 " 795 796 case "$prev" in 797 --config) 798 _filedir -d 799 return 800 ;; 801 --log-level|-l) 802 __docker_complete_log_levels 803 return 804 ;; 805 $(__docker_to_extglob "$global_options_with_args") ) 806 return 807 ;; 808 esac 809 810 case "$cur" in 811 -*) 812 COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) ) 813 ;; 814 *) 815 local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" ) 816 if [ $cword -eq $counter ]; then 817 COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) 818 fi 819 ;; 820 esac 821 } 822 823 _docker_attach() { 824 _docker_container_attach 825 } 826 827 _docker_build() { 828 _docker_image_build 829 } 830 831 832 _docker_container() { 833 local subcommands=" 834 attach 835 commit 836 cp 837 create 838 diff 839 exec 840 export 841 inspect 842 kill 843 logs 844 ls 845 pause 846 port 847 prune 848 rename 849 restart 850 rm 851 run 852 start 853 stats 854 stop 855 top 856 unpause 857 update 858 wait 859 " 860 local aliases=" 861 list 862 ps 863 " 864 __docker_subcommands "$subcommands $aliases" && return 865 866 case "$cur" in 867 -*) 868 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 869 ;; 870 *) 871 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 872 ;; 873 esac 874 } 875 876 _docker_container_attach() { 877 __docker_complete_detach-keys && return 878 879 case "$cur" in 880 -*) 881 COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) ) 882 ;; 883 *) 884 local counter=$(__docker_pos_first_nonflag '--detach-keys') 885 if [ $cword -eq $counter ]; then 886 __docker_complete_containers_running 887 fi 888 ;; 889 esac 890 } 891 892 _docker_container_commit() { 893 case "$prev" in 894 --author|-a|--change|-c|--message|-m) 895 return 896 ;; 897 esac 898 899 case "$cur" in 900 -*) 901 COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) ) 902 ;; 903 *) 904 local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m') 905 906 if [ $cword -eq $counter ]; then 907 __docker_complete_containers_all 908 return 909 fi 910 (( counter++ )) 911 912 if [ $cword -eq $counter ]; then 913 __docker_complete_image_repos_and_tags 914 return 915 fi 916 ;; 917 esac 918 } 919 920 _docker_container_cp() { 921 case "$cur" in 922 -*) 923 COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) ) 924 ;; 925 *) 926 local counter=$(__docker_pos_first_nonflag) 927 if [ $cword -eq $counter ]; then 928 case "$cur" in 929 *:) 930 return 931 ;; 932 *) 933 # combined container and filename completion 934 _filedir 935 local files=( ${COMPREPLY[@]} ) 936 937 __docker_complete_containers_all 938 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 939 local containers=( ${COMPREPLY[@]} ) 940 941 COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) ) 942 if [[ "$COMPREPLY" == *: ]]; then 943 __docker_nospace 944 fi 945 return 946 ;; 947 esac 948 fi 949 (( counter++ )) 950 951 if [ $cword -eq $counter ]; then 952 if [ -e "$prev" ]; then 953 __docker_complete_containers_all 954 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 955 __docker_nospace 956 else 957 _filedir 958 fi 959 return 960 fi 961 ;; 962 esac 963 } 964 965 _docker_container_create() { 966 _docker_container_run 967 } 968 969 _docker_container_diff() { 970 case "$cur" in 971 -*) 972 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 973 ;; 974 *) 975 local counter=$(__docker_pos_first_nonflag) 976 if [ $cword -eq $counter ]; then 977 __docker_complete_containers_all 978 fi 979 ;; 980 esac 981 } 982 983 _docker_container_exec() { 984 __docker_complete_detach-keys && return 985 986 case "$prev" in 987 --env|-e) 988 # we do not append a "=" here because "-e VARNAME" is legal systax, too 989 COMPREPLY=( $( compgen -e -- "$cur" ) ) 990 __docker_nospace 991 return 992 ;; 993 --user|-u) 994 __docker_complete_user_group 995 return 996 ;; 997 esac 998 999 case "$cur" in 1000 -*) 1001 COMPREPLY=( $( compgen -W "--detach -d --detach-keys --env -e --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) ) 1002 ;; 1003 *) 1004 __docker_complete_containers_running 1005 ;; 1006 esac 1007 } 1008 1009 _docker_container_export() { 1010 case "$cur" in 1011 -*) 1012 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1013 ;; 1014 *) 1015 local counter=$(__docker_pos_first_nonflag) 1016 if [ $cword -eq $counter ]; then 1017 __docker_complete_containers_all 1018 fi 1019 ;; 1020 esac 1021 } 1022 1023 _docker_container_inspect() { 1024 _docker_inspect --type container 1025 } 1026 1027 _docker_container_kill() { 1028 case "$prev" in 1029 --signal|-s) 1030 __docker_complete_signals 1031 return 1032 ;; 1033 esac 1034 1035 case "$cur" in 1036 -*) 1037 COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) ) 1038 ;; 1039 *) 1040 __docker_complete_containers_running 1041 ;; 1042 esac 1043 } 1044 1045 _docker_container_logs() { 1046 case "$prev" in 1047 --since|--tail) 1048 return 1049 ;; 1050 esac 1051 1052 case "$cur" in 1053 -*) 1054 COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) ) 1055 ;; 1056 *) 1057 local counter=$(__docker_pos_first_nonflag '--since|--tail') 1058 if [ $cword -eq $counter ]; then 1059 __docker_complete_containers_all 1060 fi 1061 ;; 1062 esac 1063 } 1064 1065 _docker_container_list() { 1066 _docker_container_ls 1067 } 1068 1069 _docker_container_ls() { 1070 local key=$(__docker_map_key_of_current_option '--filter|-f') 1071 case "$key" in 1072 ancestor) 1073 cur="${cur##*=}" 1074 __docker_complete_images 1075 return 1076 ;; 1077 before) 1078 __docker_complete_containers_all --cur "${cur##*=}" 1079 return 1080 ;; 1081 id) 1082 __docker_complete_containers_all --cur "${cur##*=}" --id 1083 return 1084 ;; 1085 is-task) 1086 COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) 1087 return 1088 ;; 1089 name) 1090 __docker_complete_containers_all --cur "${cur##*=}" --name 1091 return 1092 ;; 1093 network) 1094 __docker_complete_networks --cur "${cur##*=}" 1095 return 1096 ;; 1097 since) 1098 __docker_complete_containers_all --cur "${cur##*=}" 1099 return 1100 ;; 1101 status) 1102 COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) ) 1103 return 1104 ;; 1105 volume) 1106 __docker_complete_volumes --cur "${cur##*=}" 1107 return 1108 ;; 1109 esac 1110 1111 case "$prev" in 1112 --filter|-f) 1113 COMPREPLY=( $( compgen -S = -W "ancestor before exited id label name network since status volume" -- "$cur" ) ) 1114 __docker_nospace 1115 return 1116 ;; 1117 --format|--last|-n) 1118 return 1119 ;; 1120 esac 1121 1122 case "$cur" in 1123 -*) 1124 COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) ) 1125 ;; 1126 esac 1127 } 1128 1129 _docker_container_pause() { 1130 case "$cur" in 1131 -*) 1132 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1133 ;; 1134 *) 1135 local counter=$(__docker_pos_first_nonflag) 1136 if [ $cword -eq $counter ]; then 1137 __docker_complete_containers_running 1138 fi 1139 ;; 1140 esac 1141 } 1142 1143 _docker_container_port() { 1144 case "$cur" in 1145 -*) 1146 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1147 ;; 1148 *) 1149 local counter=$(__docker_pos_first_nonflag) 1150 if [ $cword -eq $counter ]; then 1151 __docker_complete_containers_all 1152 fi 1153 ;; 1154 esac 1155 } 1156 1157 # TODO new command 1158 _docker_container_prune() { 1159 : 1160 } 1161 1162 _docker_container_ps() { 1163 _docker_container_ls 1164 } 1165 1166 _docker_container_rename() { 1167 case "$cur" in 1168 -*) 1169 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1170 ;; 1171 *) 1172 local counter=$(__docker_pos_first_nonflag) 1173 if [ $cword -eq $counter ]; then 1174 __docker_complete_containers_all 1175 fi 1176 ;; 1177 esac 1178 } 1179 1180 _docker_container_restart() { 1181 case "$prev" in 1182 --time|-t) 1183 return 1184 ;; 1185 esac 1186 1187 case "$cur" in 1188 -*) 1189 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1190 ;; 1191 *) 1192 __docker_complete_containers_all 1193 ;; 1194 esac 1195 } 1196 1197 _docker_container_rm() { 1198 case "$cur" in 1199 -*) 1200 COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) 1201 ;; 1202 *) 1203 for arg in "${COMP_WORDS[@]}"; do 1204 case "$arg" in 1205 --force|-f) 1206 __docker_complete_containers_all 1207 return 1208 ;; 1209 esac 1210 done 1211 __docker_complete_containers_stopped 1212 ;; 1213 esac 1214 } 1215 1216 _docker_container_run() { 1217 local options_with_args=" 1218 --add-host 1219 --attach -a 1220 --blkio-weight 1221 --blkio-weight-device 1222 --cap-add 1223 --cap-drop 1224 --cgroup-parent 1225 --cidfile 1226 --cpu-period 1227 --cpu-quota 1228 --cpu-rt-period 1229 --cpu-rt-runtime 1230 --cpuset-cpus 1231 --cpuset-mems 1232 --cpu-shares -c 1233 --device 1234 --device-read-bps 1235 --device-read-iops 1236 --device-write-bps 1237 --device-write-iops 1238 --dns 1239 --dns-opt 1240 --dns-search 1241 --entrypoint 1242 --env -e 1243 --env-file 1244 --expose 1245 --group-add 1246 --hostname -h 1247 --ip 1248 --ip6 1249 --ipc 1250 --isolation 1251 --kernel-memory 1252 --label-file 1253 --label -l 1254 --link 1255 --link-local-ip 1256 --log-driver 1257 --log-opt 1258 --mac-address 1259 --memory -m 1260 --memory-swap 1261 --memory-swappiness 1262 --memory-reservation 1263 --name 1264 --network 1265 --network-alias 1266 --oom-score-adj 1267 --pid 1268 --pids-limit 1269 --publish -p 1270 --restart 1271 --runtime 1272 --security-opt 1273 --shm-size 1274 --stop-signal 1275 --stop-timeout 1276 --storage-opt 1277 --tmpfs 1278 --sysctl 1279 --ulimit 1280 --user -u 1281 --userns 1282 --uts 1283 --volume-driver 1284 --volumes-from 1285 --volume -v 1286 --workdir -w 1287 " 1288 1289 local boolean_options=" 1290 --disable-content-trust=false 1291 --help 1292 --interactive -i 1293 --oom-kill-disable 1294 --privileged 1295 --publish-all -P 1296 --read-only 1297 --tty -t 1298 " 1299 1300 if [ "$command" = "run" -o "$subcommand" = "run" ] ; then 1301 options_with_args="$options_with_args 1302 --detach-keys 1303 --health-cmd 1304 --health-interval 1305 --health-retries 1306 --health-timeout 1307 " 1308 boolean_options="$boolean_options 1309 --detach -d 1310 --no-healthcheck 1311 --rm 1312 --sig-proxy=false 1313 " 1314 __docker_complete_detach-keys && return 1315 fi 1316 1317 local all_options="$options_with_args $boolean_options" 1318 1319 1320 __docker_complete_log_driver_options && return 1321 __docker_complete_restart && return 1322 1323 local key=$(__docker_map_key_of_current_option '--security-opt') 1324 case "$key" in 1325 label) 1326 [[ $cur == *: ]] && return 1327 COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") ) 1328 if [ "${COMPREPLY[*]}" != "disable" ] ; then 1329 __docker_nospace 1330 fi 1331 return 1332 ;; 1333 seccomp) 1334 local cur=${cur##*=} 1335 _filedir 1336 COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) ) 1337 return 1338 ;; 1339 esac 1340 1341 case "$prev" in 1342 --add-host) 1343 case "$cur" in 1344 *:) 1345 __docker_complete_resolved_hostname 1346 return 1347 ;; 1348 esac 1349 ;; 1350 --attach|-a) 1351 COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) 1352 return 1353 ;; 1354 --cap-add|--cap-drop) 1355 __docker_complete_capabilities 1356 return 1357 ;; 1358 --cidfile|--env-file|--label-file) 1359 _filedir 1360 return 1361 ;; 1362 --device|--tmpfs|--volume|-v) 1363 case "$cur" in 1364 *:*) 1365 # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 1366 ;; 1367 '') 1368 COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) 1369 __docker_nospace 1370 ;; 1371 /*) 1372 _filedir 1373 __docker_nospace 1374 ;; 1375 esac 1376 return 1377 ;; 1378 --env|-e) 1379 # we do not append a "=" here because "-e VARNAME" is legal systax, too 1380 COMPREPLY=( $( compgen -e -- "$cur" ) ) 1381 __docker_nospace 1382 return 1383 ;; 1384 --ipc) 1385 case "$cur" in 1386 *:*) 1387 cur="${cur#*:}" 1388 __docker_complete_containers_running 1389 ;; 1390 *) 1391 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 1392 if [ "$COMPREPLY" = "container:" ]; then 1393 __docker_nospace 1394 fi 1395 ;; 1396 esac 1397 return 1398 ;; 1399 --isolation) 1400 __docker_complete_isolation 1401 return 1402 ;; 1403 --link) 1404 case "$cur" in 1405 *:*) 1406 ;; 1407 *) 1408 __docker_complete_containers_running 1409 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 1410 __docker_nospace 1411 ;; 1412 esac 1413 return 1414 ;; 1415 --log-driver) 1416 __docker_complete_log_drivers 1417 return 1418 ;; 1419 --log-opt) 1420 __docker_complete_log_options 1421 return 1422 ;; 1423 --network) 1424 case "$cur" in 1425 container:*) 1426 __docker_complete_containers_all --cur "${cur#*:}" 1427 ;; 1428 *) 1429 COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") ) 1430 if [ "${COMPREPLY[*]}" = "container:" ] ; then 1431 __docker_nospace 1432 fi 1433 ;; 1434 esac 1435 return 1436 ;; 1437 --pid) 1438 case "$cur" in 1439 *:*) 1440 __docker_complete_containers_running --cur "${cur#*:}" 1441 ;; 1442 *) 1443 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 1444 if [ "$COMPREPLY" = "container:" ]; then 1445 __docker_nospace 1446 fi 1447 ;; 1448 esac 1449 return 1450 ;; 1451 --runtime) 1452 __docker_complete_runtimes 1453 return 1454 ;; 1455 --security-opt) 1456 COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") ) 1457 if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then 1458 __docker_nospace 1459 fi 1460 return 1461 ;; 1462 --storage-opt) 1463 COMPREPLY=( $( compgen -W "size" -S = -- "$cur") ) 1464 __docker_nospace 1465 return 1466 ;; 1467 --user|-u) 1468 __docker_complete_user_group 1469 return 1470 ;; 1471 --userns) 1472 COMPREPLY=( $( compgen -W "host" -- "$cur" ) ) 1473 return 1474 ;; 1475 --volume-driver) 1476 __docker_complete_plugins --type Volume 1477 return 1478 ;; 1479 --volumes-from) 1480 __docker_complete_containers_all 1481 return 1482 ;; 1483 $(__docker_to_extglob "$options_with_args") ) 1484 return 1485 ;; 1486 esac 1487 1488 case "$cur" in 1489 -*) 1490 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 1491 ;; 1492 *) 1493 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 1494 if [ $cword -eq $counter ]; then 1495 __docker_complete_images 1496 fi 1497 ;; 1498 esac 1499 } 1500 1501 _docker_container_start() { 1502 __docker_complete_detach-keys && return 1503 1504 case "$cur" in 1505 -*) 1506 COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) ) 1507 ;; 1508 *) 1509 __docker_complete_containers_stopped 1510 ;; 1511 esac 1512 } 1513 1514 _docker_container_stats() { 1515 case "$prev" in 1516 --format) 1517 return 1518 ;; 1519 esac 1520 1521 case "$cur" in 1522 -*) 1523 COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) ) 1524 ;; 1525 *) 1526 __docker_complete_containers_running 1527 ;; 1528 esac 1529 } 1530 1531 _docker_container_stop() { 1532 case "$prev" in 1533 --time|-t) 1534 return 1535 ;; 1536 esac 1537 1538 case "$cur" in 1539 -*) 1540 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1541 ;; 1542 *) 1543 __docker_complete_containers_running 1544 ;; 1545 esac 1546 } 1547 1548 _docker_container_top() { 1549 case "$cur" in 1550 -*) 1551 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1552 ;; 1553 *) 1554 local counter=$(__docker_pos_first_nonflag) 1555 if [ $cword -eq $counter ]; then 1556 __docker_complete_containers_running 1557 fi 1558 ;; 1559 esac 1560 } 1561 1562 _docker_container_unpause() { 1563 case "$cur" in 1564 -*) 1565 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1566 ;; 1567 *) 1568 local counter=$(__docker_pos_first_nonflag) 1569 if [ $cword -eq $counter ]; then 1570 __docker_complete_containers_unpauseable 1571 fi 1572 ;; 1573 esac 1574 } 1575 1576 _docker_container_update() { 1577 local options_with_args=" 1578 --blkio-weight 1579 --cpu-period 1580 --cpu-quota 1581 --cpu-rt-period 1582 --cpu-rt-runtime 1583 --cpuset-cpus 1584 --cpuset-mems 1585 --cpu-shares -c 1586 --kernel-memory 1587 --memory -m 1588 --memory-reservation 1589 --memory-swap 1590 --restart 1591 " 1592 1593 local boolean_options=" 1594 --help 1595 " 1596 1597 local all_options="$options_with_args $boolean_options" 1598 1599 __docker_complete_restart && return 1600 1601 case "$prev" in 1602 $(__docker_to_extglob "$options_with_args") ) 1603 return 1604 ;; 1605 esac 1606 1607 case "$cur" in 1608 -*) 1609 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 1610 ;; 1611 *) 1612 __docker_complete_containers_all 1613 ;; 1614 esac 1615 } 1616 1617 _docker_container_wait() { 1618 case "$cur" in 1619 -*) 1620 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1621 ;; 1622 *) 1623 __docker_complete_containers_all 1624 ;; 1625 esac 1626 } 1627 1628 1629 _docker_commit() { 1630 _docker_container_commit 1631 } 1632 1633 _docker_cp() { 1634 _docker_container_cp 1635 } 1636 1637 _docker_create() { 1638 _docker_container_run 1639 } 1640 1641 _docker_daemon() { 1642 local boolean_options=" 1643 $global_boolean_options 1644 --disable-legacy-registry 1645 --experimental 1646 --help 1647 --icc=false 1648 --ip-forward=false 1649 --ip-masq=false 1650 --iptables=false 1651 --ipv6 1652 --live-restore 1653 --raw-logs 1654 --selinux-enabled 1655 --userland-proxy=false 1656 " 1657 local options_with_args=" 1658 $global_options_with_args 1659 --add-runtime 1660 --api-cors-header 1661 --authorization-plugin 1662 --bip 1663 --bridge -b 1664 --cgroup-parent 1665 --cluster-advertise 1666 --cluster-store 1667 --cluster-store-opt 1668 --config-file 1669 --containerd 1670 --default-gateway 1671 --default-gateway-v6 1672 --default-ulimit 1673 --dns 1674 --dns-search 1675 --dns-opt 1676 --exec-opt 1677 --exec-root 1678 --fixed-cidr 1679 --fixed-cidr-v6 1680 --graph -g 1681 --group -G 1682 --init-path 1683 --insecure-registry 1684 --ip 1685 --label 1686 --log-driver 1687 --log-opt 1688 --max-concurrent-downloads 1689 --max-concurrent-uploads 1690 --mtu 1691 --oom-score-adjust 1692 --pidfile -p 1693 --registry-mirror 1694 --shutdown-timeout 1695 --storage-driver -s 1696 --storage-opt 1697 --userns-remap 1698 " 1699 1700 __docker_complete_log_driver_options && return 1701 1702 key=$(__docker_map_key_of_current_option '--cluster-store-opt') 1703 case "$key" in 1704 kv.*file) 1705 cur=${cur##*=} 1706 _filedir 1707 return 1708 ;; 1709 esac 1710 1711 local key=$(__docker_map_key_of_current_option '--storage-opt') 1712 case "$key" in 1713 dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion) 1714 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 1715 return 1716 ;; 1717 dm.fs) 1718 COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) ) 1719 return 1720 ;; 1721 dm.thinpooldev) 1722 cur=${cur##*=} 1723 _filedir 1724 return 1725 ;; 1726 esac 1727 1728 case "$prev" in 1729 --authorization-plugin) 1730 __docker_complete_plugins --type Authorization 1731 return 1732 ;; 1733 --cluster-store) 1734 COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) ) 1735 __docker_nospace 1736 return 1737 ;; 1738 --cluster-store-opt) 1739 COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) ) 1740 __docker_nospace 1741 return 1742 ;; 1743 --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey) 1744 _filedir 1745 return 1746 ;; 1747 --exec-root|--graph|-g) 1748 _filedir -d 1749 return 1750 ;; 1751 --log-driver) 1752 __docker_complete_log_drivers 1753 return 1754 ;; 1755 --storage-driver|-s) 1756 COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) 1757 return 1758 ;; 1759 --storage-opt) 1760 local btrfs_options="btrfs.min_space" 1761 local devicemapper_options=" 1762 dm.basesize 1763 dm.blkdiscard 1764 dm.blocksize 1765 dm.fs 1766 dm.loopdatasize 1767 dm.loopmetadatasize 1768 dm.min_free_space 1769 dm.mkfsarg 1770 dm.mountopt 1771 dm.override_udev_sync_check 1772 dm.thinpooldev 1773 dm.use_deferred_deletion 1774 dm.use_deferred_removal 1775 " 1776 local zfs_options="zfs.fsname" 1777 1778 case $(__docker_value_of_option '--storage-driver|-s') in 1779 '') 1780 COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) ) 1781 ;; 1782 btrfs) 1783 COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) ) 1784 ;; 1785 devicemapper) 1786 COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) ) 1787 ;; 1788 zfs) 1789 COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) ) 1790 ;; 1791 *) 1792 return 1793 ;; 1794 esac 1795 __docker_nospace 1796 return 1797 ;; 1798 --log-level|-l) 1799 __docker_complete_log_levels 1800 return 1801 ;; 1802 --log-opt) 1803 __docker_complete_log_options 1804 return 1805 ;; 1806 --userns-remap) 1807 __docker_complete_user_group 1808 return 1809 ;; 1810 $(__docker_to_extglob "$options_with_args") ) 1811 return 1812 ;; 1813 esac 1814 1815 case "$cur" in 1816 -*) 1817 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 1818 ;; 1819 esac 1820 } 1821 1822 _docker_diff() { 1823 _docker_container_diff 1824 } 1825 1826 _docker_events() { 1827 local key=$(__docker_map_key_of_current_option '-f|--filter') 1828 case "$key" in 1829 container) 1830 __docker_complete_containers_all --cur "${cur##*=}" 1831 return 1832 ;; 1833 daemon) 1834 local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p') 1835 COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) ) 1836 return 1837 ;; 1838 event) 1839 COMPREPLY=( $( compgen -W " 1840 attach 1841 commit 1842 connect 1843 copy 1844 create 1845 delete 1846 destroy 1847 detach 1848 die 1849 disconnect 1850 exec_create 1851 exec_detach 1852 exec_start 1853 export 1854 health_status 1855 import 1856 kill 1857 load 1858 mount 1859 oom 1860 pause 1861 pull 1862 push 1863 reload 1864 rename 1865 resize 1866 restart 1867 save 1868 start 1869 stop 1870 tag 1871 top 1872 unmount 1873 unpause 1874 untag 1875 update 1876 " -- "${cur##*=}" ) ) 1877 return 1878 ;; 1879 image) 1880 cur="${cur##*=}" 1881 __docker_complete_images 1882 return 1883 ;; 1884 network) 1885 __docker_complete_networks --cur "${cur##*=}" 1886 return 1887 ;; 1888 type) 1889 COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) ) 1890 return 1891 ;; 1892 volume) 1893 __docker_complete_volumes --cur "${cur##*=}" 1894 return 1895 ;; 1896 esac 1897 1898 case "$prev" in 1899 --filter|-f) 1900 COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) ) 1901 __docker_nospace 1902 return 1903 ;; 1904 --since|--until) 1905 return 1906 ;; 1907 esac 1908 1909 case "$cur" in 1910 -*) 1911 COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) ) 1912 ;; 1913 esac 1914 } 1915 1916 _docker_exec() { 1917 _docker_container_exec 1918 } 1919 1920 _docker_export() { 1921 _docker_container_export 1922 } 1923 1924 _docker_help() { 1925 local counter=$(__docker_pos_first_nonflag) 1926 if [ $cword -eq $counter ]; then 1927 COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) 1928 fi 1929 } 1930 1931 _docker_history() { 1932 _docker_image_history 1933 } 1934 1935 1936 _docker_image() { 1937 local subcommands=" 1938 build 1939 history 1940 import 1941 inspect 1942 load 1943 ls 1944 prune 1945 pull 1946 push 1947 rm 1948 save 1949 tag 1950 " 1951 local aliases=" 1952 images 1953 list 1954 remove 1955 rmi 1956 " 1957 __docker_subcommands "$subcommands $aliases" && return 1958 1959 case "$cur" in 1960 -*) 1961 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1962 ;; 1963 *) 1964 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1965 ;; 1966 esac 1967 } 1968 1969 _docker_image_build() { 1970 local options_with_args=" 1971 --build-arg 1972 --cgroup-parent 1973 --cpuset-cpus 1974 --cpuset-mems 1975 --cpu-shares -c 1976 --cpu-period 1977 --cpu-quota 1978 --file -f 1979 --isolation 1980 --label 1981 --memory -m 1982 --memory-swap 1983 --shm-size 1984 --tag -t 1985 --ulimit 1986 " 1987 1988 local boolean_options=" 1989 --compress 1990 --disable-content-trust=false 1991 --force-rm 1992 --help 1993 --no-cache 1994 --pull 1995 --quiet -q 1996 --rm 1997 " 1998 1999 local all_options="$options_with_args $boolean_options" 2000 2001 case "$prev" in 2002 --build-arg) 2003 COMPREPLY=( $( compgen -e -- "$cur" ) ) 2004 __docker_nospace 2005 return 2006 ;; 2007 --file|-f) 2008 _filedir 2009 return 2010 ;; 2011 --isolation) 2012 __docker_complete_isolation 2013 return 2014 ;; 2015 --tag|-t) 2016 __docker_complete_image_repos_and_tags 2017 return 2018 ;; 2019 $(__docker_to_extglob "$options_with_args") ) 2020 return 2021 ;; 2022 esac 2023 2024 case "$cur" in 2025 -*) 2026 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 2027 ;; 2028 *) 2029 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 2030 if [ $cword -eq $counter ]; then 2031 _filedir -d 2032 fi 2033 ;; 2034 esac 2035 } 2036 2037 _docker_image_history() { 2038 case "$cur" in 2039 -*) 2040 COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) ) 2041 ;; 2042 *) 2043 local counter=$(__docker_pos_first_nonflag) 2044 if [ $cword -eq $counter ]; then 2045 __docker_complete_images 2046 fi 2047 ;; 2048 esac 2049 } 2050 2051 _docker_image_images() { 2052 _docker_image_ls 2053 } 2054 2055 _docker_image_import() { 2056 case "$prev" in 2057 --change|-c|--message|-m) 2058 return 2059 ;; 2060 esac 2061 2062 case "$cur" in 2063 -*) 2064 COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) ) 2065 ;; 2066 *) 2067 local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m') 2068 if [ $cword -eq $counter ]; then 2069 return 2070 fi 2071 (( counter++ )) 2072 2073 if [ $cword -eq $counter ]; then 2074 __docker_complete_image_repos_and_tags 2075 return 2076 fi 2077 ;; 2078 esac 2079 } 2080 2081 _docker_image_inspect() { 2082 _docker_inspect --type image 2083 } 2084 2085 _docker_image_load() { 2086 case "$prev" in 2087 --input|-i) 2088 _filedir 2089 return 2090 ;; 2091 esac 2092 2093 case "$cur" in 2094 -*) 2095 COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) ) 2096 ;; 2097 esac 2098 } 2099 2100 _docker_image_list() { 2101 _docker_image_ls 2102 } 2103 2104 _docker_image_ls() { 2105 local key=$(__docker_map_key_of_current_option '--filter|-f') 2106 case "$key" in 2107 before) 2108 cur="${cur##*=}" 2109 __docker_complete_images 2110 return 2111 ;; 2112 dangling) 2113 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 2114 return 2115 ;; 2116 label) 2117 return 2118 ;; 2119 since) 2120 cur="${cur##*=}" 2121 __docker_complete_images 2122 return 2123 ;; 2124 esac 2125 2126 case "$prev" in 2127 --filter|-f) 2128 COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) ) 2129 __docker_nospace 2130 return 2131 ;; 2132 --format) 2133 return 2134 ;; 2135 esac 2136 2137 case "$cur" in 2138 -*) 2139 COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) 2140 ;; 2141 =) 2142 return 2143 ;; 2144 *) 2145 __docker_complete_image_repos 2146 ;; 2147 esac 2148 } 2149 2150 # TODO new command 2151 _docker_image_prune() { 2152 : 2153 } 2154 2155 _docker_image_pull() { 2156 case "$cur" in 2157 -*) 2158 COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) ) 2159 ;; 2160 *) 2161 local counter=$(__docker_pos_first_nonflag) 2162 if [ $cword -eq $counter ]; then 2163 for arg in "${COMP_WORDS[@]}"; do 2164 case "$arg" in 2165 --all-tags|-a) 2166 __docker_complete_image_repos 2167 return 2168 ;; 2169 esac 2170 done 2171 __docker_complete_image_repos_and_tags 2172 fi 2173 ;; 2174 esac 2175 } 2176 2177 _docker_image_push() { 2178 case "$cur" in 2179 -*) 2180 COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) ) 2181 ;; 2182 *) 2183 local counter=$(__docker_pos_first_nonflag) 2184 if [ $cword -eq $counter ]; then 2185 __docker_complete_image_repos_and_tags 2186 fi 2187 ;; 2188 esac 2189 } 2190 2191 _docker_image_remove() { 2192 _docker_image_rm 2193 } 2194 2195 _docker_image_rm() { 2196 case "$cur" in 2197 -*) 2198 COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) 2199 ;; 2200 *) 2201 __docker_complete_images 2202 ;; 2203 esac 2204 } 2205 2206 _docker_image_rmi() { 2207 _docker_image_rm 2208 } 2209 2210 _docker_image_save() { 2211 case "$prev" in 2212 --output|-o) 2213 _filedir 2214 return 2215 ;; 2216 esac 2217 2218 case "$cur" in 2219 -*) 2220 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 2221 ;; 2222 *) 2223 __docker_complete_images 2224 ;; 2225 esac 2226 } 2227 2228 _docker_image_tag() { 2229 case "$cur" in 2230 -*) 2231 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2232 ;; 2233 *) 2234 local counter=$(__docker_pos_first_nonflag) 2235 2236 if [ $cword -eq $counter ]; then 2237 __docker_complete_image_repos_and_tags 2238 return 2239 fi 2240 (( counter++ )) 2241 2242 if [ $cword -eq $counter ]; then 2243 __docker_complete_image_repos_and_tags 2244 return 2245 fi 2246 ;; 2247 esac 2248 } 2249 2250 2251 _docker_images() { 2252 _docker_image_ls 2253 } 2254 2255 _docker_import() { 2256 _docker_image_import 2257 } 2258 2259 _docker_info() { 2260 case "$prev" in 2261 --format|-f) 2262 return 2263 ;; 2264 esac 2265 2266 case "$cur" in 2267 -*) 2268 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 2269 ;; 2270 esac 2271 } 2272 2273 _docker_inspect() { 2274 local type 2275 2276 if [ "$1" = "--type" ] ; then 2277 type="$2" 2278 else 2279 type=$(__docker_value_of_option --type) 2280 fi 2281 2282 case "$prev" in 2283 --format|-f) 2284 return 2285 ;; 2286 --type) 2287 if [ -z "$type" ] ; then 2288 COMPREPLY=( $( compgen -W "image container" -- "$cur" ) ) 2289 fi 2290 return 2291 ;; 2292 esac 2293 2294 case "$cur" in 2295 -*) 2296 local options="--format -f --help --size -s" 2297 if [ -z "$type" ] ; then 2298 options+=" --type" 2299 fi 2300 COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) 2301 ;; 2302 *) 2303 case "$type" in 2304 '') 2305 __docker_complete_containers_and_images 2306 ;; 2307 container) 2308 __docker_complete_containers_all 2309 ;; 2310 image) 2311 __docker_complete_images 2312 ;; 2313 esac 2314 esac 2315 } 2316 2317 _docker_kill() { 2318 _docker_container_kill 2319 } 2320 2321 _docker_load() { 2322 _docker_image_load 2323 } 2324 2325 _docker_login() { 2326 case "$prev" in 2327 --password|-p|--username|-u) 2328 return 2329 ;; 2330 esac 2331 2332 case "$cur" in 2333 -*) 2334 COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) ) 2335 ;; 2336 esac 2337 } 2338 2339 _docker_logout() { 2340 case "$cur" in 2341 -*) 2342 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2343 ;; 2344 esac 2345 } 2346 2347 _docker_logs() { 2348 _docker_container_logs 2349 } 2350 2351 _docker_network_connect() { 2352 local options_with_args=" 2353 --alias 2354 --ip 2355 --ip6 2356 --link 2357 --link-local-ip 2358 " 2359 2360 local boolean_options=" 2361 --help 2362 " 2363 2364 case "$prev" in 2365 --link) 2366 case "$cur" in 2367 *:*) 2368 ;; 2369 *) 2370 __docker_complete_containers_running 2371 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 2372 __docker_nospace 2373 ;; 2374 esac 2375 return 2376 ;; 2377 $(__docker_to_extglob "$options_with_args") ) 2378 return 2379 ;; 2380 esac 2381 2382 case "$cur" in 2383 -*) 2384 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 2385 ;; 2386 *) 2387 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 2388 if [ $cword -eq $counter ]; then 2389 __docker_complete_networks 2390 elif [ $cword -eq $(($counter + 1)) ]; then 2391 __docker_complete_containers_all 2392 fi 2393 ;; 2394 esac 2395 } 2396 2397 _docker_network_create() { 2398 case "$prev" in 2399 --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet) 2400 return 2401 ;; 2402 --ipam-driver) 2403 COMPREPLY=( $( compgen -W "default" -- "$cur" ) ) 2404 return 2405 ;; 2406 --driver|-d) 2407 # remove drivers that allow one instance only, add drivers missing in `docker info` 2408 __docker_complete_plugins --type Network --remove host --remove null --add macvlan 2409 return 2410 ;; 2411 --label) 2412 return 2413 ;; 2414 esac 2415 2416 case "$cur" in 2417 -*) 2418 COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) ) 2419 ;; 2420 esac 2421 } 2422 2423 _docker_network_disconnect() { 2424 case "$cur" in 2425 -*) 2426 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2427 ;; 2428 *) 2429 local counter=$(__docker_pos_first_nonflag) 2430 if [ $cword -eq $counter ]; then 2431 __docker_complete_networks 2432 elif [ $cword -eq $(($counter + 1)) ]; then 2433 __docker_complete_containers_in_network "$prev" 2434 fi 2435 ;; 2436 esac 2437 } 2438 2439 _docker_network_inspect() { 2440 case "$prev" in 2441 --format|-f) 2442 return 2443 ;; 2444 esac 2445 2446 case "$cur" in 2447 -*) 2448 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 2449 ;; 2450 *) 2451 __docker_complete_networks 2452 esac 2453 } 2454 2455 _docker_network_ls() { 2456 local key=$(__docker_map_key_of_current_option '--filter|-f') 2457 case "$key" in 2458 driver) 2459 __docker_complete_plugins --cur "${cur##*=}" --type Network --add macvlan 2460 return 2461 ;; 2462 id) 2463 __docker_complete_networks --cur "${cur##*=}" --id 2464 return 2465 ;; 2466 name) 2467 __docker_complete_networks --cur "${cur##*=}" --name 2468 return 2469 ;; 2470 type) 2471 COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) ) 2472 return 2473 ;; 2474 esac 2475 2476 case "$prev" in 2477 --filter|-f) 2478 COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) ) 2479 __docker_nospace 2480 return 2481 ;; 2482 --format) 2483 return 2484 ;; 2485 esac 2486 2487 case "$cur" in 2488 -*) 2489 COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) 2490 ;; 2491 esac 2492 } 2493 2494 _docker_network_rm() { 2495 case "$cur" in 2496 -*) 2497 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2498 ;; 2499 *) 2500 __docker_complete_networks --filter type=custom 2501 esac 2502 } 2503 2504 _docker_network() { 2505 local subcommands=" 2506 connect 2507 create 2508 disconnect 2509 inspect 2510 ls 2511 rm 2512 " 2513 __docker_subcommands "$subcommands" && return 2514 2515 case "$cur" in 2516 -*) 2517 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2518 ;; 2519 *) 2520 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2521 ;; 2522 esac 2523 } 2524 2525 _docker_service() { 2526 local subcommands=" 2527 create 2528 inspect 2529 ls list 2530 rm remove 2531 scale 2532 ps 2533 update 2534 " 2535 __docker_subcommands "$subcommands" && return 2536 2537 case "$cur" in 2538 -*) 2539 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2540 ;; 2541 *) 2542 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2543 ;; 2544 esac 2545 } 2546 2547 _docker_service_create() { 2548 _docker_service_update 2549 } 2550 2551 _docker_service_inspect() { 2552 case "$prev" in 2553 --format|-f) 2554 return 2555 ;; 2556 esac 2557 2558 case "$cur" in 2559 -*) 2560 COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) 2561 ;; 2562 *) 2563 __docker_complete_services 2564 esac 2565 } 2566 2567 _docker_service_list() { 2568 _docker_service_ls 2569 } 2570 2571 _docker_service_ls() { 2572 local key=$(__docker_map_key_of_current_option '--filter|-f') 2573 case "$key" in 2574 id) 2575 __docker_complete_services --cur "${cur##*=}" --id 2576 return 2577 ;; 2578 name) 2579 __docker_complete_services --cur "${cur##*=}" --name 2580 return 2581 ;; 2582 esac 2583 2584 case "$prev" in 2585 --filter|-f) 2586 COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) 2587 __docker_nospace 2588 return 2589 ;; 2590 esac 2591 2592 case "$cur" in 2593 -*) 2594 COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) 2595 ;; 2596 esac 2597 } 2598 2599 _docker_service_remove() { 2600 _docker_service_rm 2601 } 2602 2603 _docker_service_rm() { 2604 case "$cur" in 2605 -*) 2606 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2607 ;; 2608 *) 2609 __docker_complete_services 2610 esac 2611 } 2612 2613 _docker_service_scale() { 2614 case "$cur" in 2615 -*) 2616 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2617 ;; 2618 *) 2619 __docker_complete_services 2620 __docker_append_to_completions "=" 2621 __docker_nospace 2622 ;; 2623 esac 2624 } 2625 2626 _docker_service_ps() { 2627 local key=$(__docker_map_key_of_current_option '--filter|-f') 2628 case "$key" in 2629 desired-state) 2630 COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) 2631 return 2632 ;; 2633 name) 2634 __docker_complete_services --cur "${cur##*=}" --name 2635 return 2636 ;; 2637 esac 2638 2639 case "$prev" in 2640 --filter|-f) 2641 COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) ) 2642 __docker_nospace 2643 return 2644 ;; 2645 esac 2646 2647 case "$cur" in 2648 -*) 2649 COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) ) 2650 ;; 2651 *) 2652 local counter=$(__docker_pos_first_nonflag '--filter|-f') 2653 if [ $cword -eq $counter ]; then 2654 __docker_complete_services 2655 fi 2656 ;; 2657 esac 2658 } 2659 2660 _docker_service_update() { 2661 local $subcommand="${words[$subcommand_pos]}" 2662 2663 local options_with_args=" 2664 --constraint 2665 --endpoint-mode 2666 --env -e 2667 --force 2668 --group-add 2669 --label -l 2670 --limit-cpu 2671 --limit-memory 2672 --log-driver 2673 --log-opt 2674 --mount 2675 --name 2676 --network 2677 --publish -p 2678 --replicas 2679 --reserve-cpu 2680 --reserve-memory 2681 --restart-condition 2682 --restart-delay 2683 --restart-max-attempts 2684 --restart-window 2685 --rollback 2686 --stop-grace-period 2687 --update-delay 2688 --update-failure-action 2689 --update-max-failure-ratio 2690 --update-monitor 2691 --update-parallelism 2692 --user -u 2693 --workdir -w 2694 " 2695 2696 local boolean_options=" 2697 --help 2698 --with-registry-auth 2699 " 2700 2701 __docker_complete_log_driver_options && return 2702 2703 if [ "$subcommand" = "create" ] ; then 2704 options_with_args="$options_with_args 2705 --container-label 2706 --mode 2707 " 2708 2709 case "$prev" in 2710 --mode) 2711 COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) ) 2712 return 2713 ;; 2714 esac 2715 fi 2716 if [ "$subcommand" = "update" ] ; then 2717 options_with_args="$options_with_args 2718 --arg 2719 --container-label-add 2720 --container-label-rm 2721 --group-rm 2722 --image 2723 " 2724 2725 case "$prev" in 2726 --group-rm) 2727 COMPREPLY=( $(compgen -g -- "$cur") ) 2728 return 2729 ;; 2730 --image) 2731 __docker_complete_image_repos_and_tags 2732 return 2733 ;; 2734 esac 2735 fi 2736 2737 case "$prev" in 2738 --endpoint-mode) 2739 COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) ) 2740 return 2741 ;; 2742 --env|-e) 2743 # we do not append a "=" here because "-e VARNAME" is legal systax, too 2744 COMPREPLY=( $( compgen -e -- "$cur" ) ) 2745 __docker_nospace 2746 return 2747 ;; 2748 --group-add) 2749 COMPREPLY=( $(compgen -g -- "$cur") ) 2750 return 2751 ;; 2752 --log-driver) 2753 __docker_complete_log_drivers 2754 return 2755 ;; 2756 --log-opt) 2757 __docker_complete_log_options 2758 return 2759 ;; 2760 --network) 2761 __docker_complete_networks 2762 return 2763 ;; 2764 --restart-condition) 2765 COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) ) 2766 return 2767 ;; 2768 --user|-u) 2769 __docker_complete_user_group 2770 return 2771 ;; 2772 $(__docker_to_extglob "$options_with_args") ) 2773 return 2774 ;; 2775 esac 2776 2777 case "$cur" in 2778 -*) 2779 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 2780 ;; 2781 *) 2782 if [ "$subcommand" = "update" ] ; then 2783 __docker_complete_services 2784 fi 2785 esac 2786 } 2787 2788 _docker_swarm() { 2789 local subcommands=" 2790 init 2791 join 2792 join-token 2793 leave 2794 update 2795 " 2796 __docker_subcommands "$subcommands" && return 2797 2798 case "$cur" in 2799 -*) 2800 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2801 ;; 2802 *) 2803 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2804 ;; 2805 esac 2806 } 2807 2808 _docker_swarm_init() { 2809 case "$prev" in 2810 --advertise-addr) 2811 if [[ $cur == *: ]] ; then 2812 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2813 else 2814 __docker_complete_local_interfaces 2815 __docker_nospace 2816 fi 2817 return 2818 ;; 2819 --listen-addr) 2820 if [[ $cur == *: ]] ; then 2821 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2822 else 2823 __docker_complete_local_interfaces --add 0.0.0.0 2824 __docker_nospace 2825 fi 2826 return 2827 ;; 2828 esac 2829 2830 case "$cur" in 2831 -*) 2832 COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) ) 2833 ;; 2834 esac 2835 } 2836 2837 _docker_swarm_join() { 2838 case "$prev" in 2839 --advertise-addr) 2840 if [[ $cur == *: ]] ; then 2841 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2842 else 2843 __docker_complete_local_interfaces 2844 __docker_nospace 2845 fi 2846 return 2847 ;; 2848 --listen-addr) 2849 if [[ $cur == *: ]] ; then 2850 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2851 else 2852 __docker_complete_local_interfaces --add 0.0.0.0 2853 __docker_nospace 2854 fi 2855 return 2856 ;; 2857 --token) 2858 return 2859 ;; 2860 esac 2861 2862 case "$cur" in 2863 -*) 2864 COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) ) 2865 ;; 2866 *:) 2867 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2868 ;; 2869 esac 2870 } 2871 2872 _docker_swarm_join-token() { 2873 case "$cur" in 2874 -*) 2875 COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) ) 2876 ;; 2877 *) 2878 local counter=$( __docker_pos_first_nonflag ) 2879 if [ $cword -eq $counter ]; then 2880 COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) 2881 fi 2882 ;; 2883 esac 2884 } 2885 2886 _docker_swarm_leave() { 2887 case "$cur" in 2888 -*) 2889 COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) ) 2890 ;; 2891 esac 2892 } 2893 2894 _docker_swarm_update() { 2895 case "$prev" in 2896 --cert-expiry|--dispatcher-heartbeat|--task-history-limit) 2897 return 2898 ;; 2899 esac 2900 2901 case "$cur" in 2902 -*) 2903 COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) ) 2904 ;; 2905 esac 2906 } 2907 2908 _docker_node() { 2909 local subcommands=" 2910 demote 2911 inspect 2912 ls list 2913 promote 2914 rm remove 2915 ps 2916 update 2917 " 2918 __docker_subcommands "$subcommands" && return 2919 2920 case "$cur" in 2921 -*) 2922 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2923 ;; 2924 *) 2925 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2926 ;; 2927 esac 2928 } 2929 2930 _docker_node_demote() { 2931 case "$cur" in 2932 -*) 2933 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2934 ;; 2935 *) 2936 __docker_complete_nodes --filter role=manager 2937 esac 2938 } 2939 2940 _docker_node_inspect() { 2941 case "$prev" in 2942 --format|-f) 2943 return 2944 ;; 2945 esac 2946 2947 case "$cur" in 2948 -*) 2949 COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) 2950 ;; 2951 *) 2952 __docker_complete_nodes_plus_self 2953 esac 2954 } 2955 2956 _docker_node_list() { 2957 _docker_node_ls 2958 } 2959 2960 _docker_node_ls() { 2961 local key=$(__docker_map_key_of_current_option '--filter|-f') 2962 case "$key" in 2963 id) 2964 __docker_complete_nodes --cur "${cur##*=}" --id 2965 return 2966 ;; 2967 name) 2968 __docker_complete_nodes --cur "${cur##*=}" --name 2969 return 2970 ;; 2971 esac 2972 2973 case "$prev" in 2974 --filter|-f) 2975 COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) 2976 __docker_nospace 2977 return 2978 ;; 2979 esac 2980 2981 case "$cur" in 2982 -*) 2983 COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) 2984 ;; 2985 esac 2986 } 2987 2988 _docker_node_promote() { 2989 case "$cur" in 2990 -*) 2991 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2992 ;; 2993 *) 2994 __docker_complete_nodes --filter role=worker 2995 esac 2996 } 2997 2998 _docker_node_remove() { 2999 _docker_node_rm 3000 } 3001 3002 _docker_node_rm() { 3003 case "$cur" in 3004 -*) 3005 COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) ) 3006 ;; 3007 *) 3008 __docker_complete_nodes 3009 esac 3010 } 3011 3012 _docker_node_ps() { 3013 local key=$(__docker_map_key_of_current_option '--filter|-f') 3014 case "$key" in 3015 desired-state) 3016 COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) 3017 return 3018 ;; 3019 name) 3020 __docker_complete_services --cur "${cur##*=}" --name 3021 return 3022 ;; 3023 esac 3024 3025 case "$prev" in 3026 --filter|-f) 3027 COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) ) 3028 __docker_nospace 3029 return 3030 ;; 3031 esac 3032 3033 case "$cur" in 3034 -*) 3035 COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) ) 3036 ;; 3037 *) 3038 __docker_complete_nodes_plus_self 3039 ;; 3040 esac 3041 } 3042 3043 _docker_node_update() { 3044 case "$prev" in 3045 --availability) 3046 COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) ) 3047 return 3048 ;; 3049 --role) 3050 COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) 3051 return 3052 ;; 3053 --label-add|--label-rm) 3054 return 3055 ;; 3056 esac 3057 3058 case "$cur" in 3059 -*) 3060 COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) ) 3061 ;; 3062 *) 3063 __docker_complete_nodes 3064 esac 3065 } 3066 3067 _docker_pause() { 3068 _docker_container_pause 3069 } 3070 3071 _docker_port() { 3072 _docker_container_port 3073 } 3074 3075 _docker_ps() { 3076 _docker_container_ls 3077 } 3078 3079 _docker_pull() { 3080 _docker_image_pull 3081 } 3082 3083 _docker_push() { 3084 _docker_image_push 3085 } 3086 3087 _docker_rename() { 3088 _docker_container_rename 3089 } 3090 3091 _docker_restart() { 3092 _docker_container_restart 3093 } 3094 3095 _docker_rm() { 3096 _docker_container_rm 3097 } 3098 3099 _docker_rmi() { 3100 _docker_image_rm 3101 } 3102 3103 _docker_run() { 3104 _docker_container_run 3105 } 3106 3107 _docker_save() { 3108 _docker_image_save 3109 } 3110 3111 _docker_search() { 3112 local key=$(__docker_map_key_of_current_option '--filter|-f') 3113 case "$key" in 3114 is-automated) 3115 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 3116 return 3117 ;; 3118 is-official) 3119 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 3120 return 3121 ;; 3122 esac 3123 3124 case "$prev" in 3125 --filter|-f) 3126 COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) ) 3127 __docker_nospace 3128 return 3129 ;; 3130 --limit) 3131 return 3132 ;; 3133 esac 3134 3135 case "$cur" in 3136 -*) 3137 COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) ) 3138 ;; 3139 esac 3140 } 3141 3142 _docker_start() { 3143 _docker_container_start 3144 } 3145 3146 _docker_stats() { 3147 _docker_container_stats 3148 } 3149 3150 _docker_stop() { 3151 _docker_container_stop 3152 } 3153 3154 _docker_tag() { 3155 _docker_image_tag 3156 } 3157 3158 _docker_unpause() { 3159 _docker_container_unpause 3160 } 3161 3162 _docker_update() { 3163 _docker_container_update 3164 } 3165 3166 _docker_top() { 3167 _docker_container_top 3168 } 3169 3170 _docker_version() { 3171 case "$cur" in 3172 -*) 3173 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 3174 ;; 3175 esac 3176 } 3177 3178 _docker_volume_create() { 3179 case "$prev" in 3180 --driver|-d) 3181 __docker_complete_plugins --type Volume 3182 return 3183 ;; 3184 --label|--opt|-o) 3185 return 3186 ;; 3187 esac 3188 3189 case "$cur" in 3190 -*) 3191 COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) ) 3192 ;; 3193 esac 3194 } 3195 3196 _docker_volume_inspect() { 3197 case "$prev" in 3198 --format|-f) 3199 return 3200 ;; 3201 esac 3202 3203 case "$cur" in 3204 -*) 3205 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 3206 ;; 3207 *) 3208 __docker_complete_volumes 3209 ;; 3210 esac 3211 } 3212 3213 _docker_volume_ls() { 3214 local key=$(__docker_map_key_of_current_option '--filter|-f') 3215 case "$key" in 3216 dangling) 3217 COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) 3218 return 3219 ;; 3220 driver) 3221 __docker_complete_plugins --cur "${cur##*=}" --type Volume 3222 return 3223 ;; 3224 name) 3225 __docker_complete_volumes --cur "${cur##*=}" 3226 return 3227 ;; 3228 esac 3229 3230 case "$prev" in 3231 --filter|-f) 3232 COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) ) 3233 __docker_nospace 3234 return 3235 ;; 3236 --format) 3237 return 3238 ;; 3239 esac 3240 3241 case "$cur" in 3242 -*) 3243 COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) ) 3244 ;; 3245 esac 3246 } 3247 3248 _docker_volume_rm() { 3249 case "$cur" in 3250 -*) 3251 COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) 3252 ;; 3253 *) 3254 __docker_complete_volumes 3255 ;; 3256 esac 3257 } 3258 3259 _docker_volume() { 3260 local subcommands=" 3261 create 3262 inspect 3263 ls 3264 rm 3265 " 3266 __docker_subcommands "$subcommands" && return 3267 3268 case "$cur" in 3269 -*) 3270 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 3271 ;; 3272 *) 3273 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 3274 ;; 3275 esac 3276 } 3277 3278 _docker_wait() { 3279 _docker_container_wait 3280 } 3281 3282 _docker() { 3283 local previous_extglob_setting=$(shopt -p extglob) 3284 shopt -s extglob 3285 3286 local commands=( 3287 attach 3288 build 3289 commit 3290 container 3291 cp 3292 create 3293 daemon 3294 diff 3295 events 3296 exec 3297 export 3298 history 3299 image 3300 images 3301 import 3302 info 3303 inspect 3304 kill 3305 load 3306 login 3307 logout 3308 logs 3309 network 3310 node 3311 pause 3312 port 3313 ps 3314 pull 3315 push 3316 rename 3317 restart 3318 rm 3319 rmi 3320 run 3321 save 3322 search 3323 service 3324 start 3325 stats 3326 stop 3327 swarm 3328 tag 3329 top 3330 unpause 3331 update 3332 version 3333 volume 3334 wait 3335 ) 3336 3337 # These options are valid as global options for all client commands 3338 # and valid as command options for `docker daemon` 3339 local global_boolean_options=" 3340 --debug -D 3341 --tls 3342 --tlsverify 3343 " 3344 local global_options_with_args=" 3345 --config 3346 --host -H 3347 --log-level -l 3348 --tlscacert 3349 --tlscert 3350 --tlskey 3351 " 3352 3353 local host config 3354 3355 COMPREPLY=() 3356 local cur prev words cword 3357 _get_comp_words_by_ref -n : cur prev words cword 3358 3359 local command='docker' command_pos=0 subcommand_pos 3360 local counter=1 3361 while [ $counter -lt $cword ]; do 3362 case "${words[$counter]}" in 3363 # save host so that completion can use custom daemon 3364 --host|-H) 3365 (( counter++ )) 3366 host="${words[$counter]}" 3367 ;; 3368 # save config so that completion can use custom configuration directories 3369 --config) 3370 (( counter++ )) 3371 config="${words[$counter]}" 3372 ;; 3373 $(__docker_to_extglob "$global_options_with_args") ) 3374 (( counter++ )) 3375 ;; 3376 -*) 3377 ;; 3378 =) 3379 (( counter++ )) 3380 ;; 3381 *) 3382 command="${words[$counter]}" 3383 command_pos=$counter 3384 break 3385 ;; 3386 esac 3387 (( counter++ )) 3388 done 3389 3390 local binary="${words[0]}" 3391 if [[ $binary == ?(*/)dockerd ]] ; then 3392 # for the dockerd binary, we reuse completion of `docker daemon`. 3393 # dockerd does not have subcommands and global options. 3394 command=daemon 3395 command_pos=0 3396 fi 3397 3398 local completions_func=_docker_${command} 3399 declare -F $completions_func >/dev/null && $completions_func 3400 3401 eval "$previous_extglob_setting" 3402 return 0 3403 } 3404 3405 eval "$__docker_previous_extglob_setting" 3406 unset __docker_previous_extglob_setting 3407 3408 complete -F _docker docker dockerd