github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/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 "$prev" in 1011 --output|-o) 1012 _filedir 1013 return 1014 ;; 1015 esac 1016 1017 case "$cur" in 1018 -*) 1019 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 1020 ;; 1021 *) 1022 local counter=$(__docker_pos_first_nonflag) 1023 if [ $cword -eq $counter ]; then 1024 __docker_complete_containers_all 1025 fi 1026 ;; 1027 esac 1028 } 1029 1030 _docker_container_inspect() { 1031 _docker_inspect --type container 1032 } 1033 1034 _docker_container_kill() { 1035 case "$prev" in 1036 --signal|-s) 1037 __docker_complete_signals 1038 return 1039 ;; 1040 esac 1041 1042 case "$cur" in 1043 -*) 1044 COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) ) 1045 ;; 1046 *) 1047 __docker_complete_containers_running 1048 ;; 1049 esac 1050 } 1051 1052 _docker_container_logs() { 1053 case "$prev" in 1054 --since|--tail) 1055 return 1056 ;; 1057 esac 1058 1059 case "$cur" in 1060 -*) 1061 COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) ) 1062 ;; 1063 *) 1064 local counter=$(__docker_pos_first_nonflag '--since|--tail') 1065 if [ $cword -eq $counter ]; then 1066 __docker_complete_containers_all 1067 fi 1068 ;; 1069 esac 1070 } 1071 1072 _docker_container_list() { 1073 _docker_container_ls 1074 } 1075 1076 _docker_container_ls() { 1077 local key=$(__docker_map_key_of_current_option '--filter|-f') 1078 case "$key" in 1079 ancestor) 1080 cur="${cur##*=}" 1081 __docker_complete_images 1082 return 1083 ;; 1084 before) 1085 __docker_complete_containers_all --cur "${cur##*=}" 1086 return 1087 ;; 1088 id) 1089 __docker_complete_containers_all --cur "${cur##*=}" --id 1090 return 1091 ;; 1092 health) 1093 COMPREPLY=( $( compgen -W "healthy starting none unhealthy" -- "${cur##*=}" ) ) 1094 return 1095 ;; 1096 is-task) 1097 COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) 1098 return 1099 ;; 1100 name) 1101 __docker_complete_containers_all --cur "${cur##*=}" --name 1102 return 1103 ;; 1104 network) 1105 __docker_complete_networks --cur "${cur##*=}" 1106 return 1107 ;; 1108 since) 1109 __docker_complete_containers_all --cur "${cur##*=}" 1110 return 1111 ;; 1112 status) 1113 COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) ) 1114 return 1115 ;; 1116 volume) 1117 __docker_complete_volumes --cur "${cur##*=}" 1118 return 1119 ;; 1120 esac 1121 1122 case "$prev" in 1123 --filter|-f) 1124 COMPREPLY=( $( compgen -S = -W "ancestor before exited health id label name network since status volume" -- "$cur" ) ) 1125 __docker_nospace 1126 return 1127 ;; 1128 --format|--last|-n) 1129 return 1130 ;; 1131 esac 1132 1133 case "$cur" in 1134 -*) 1135 COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) ) 1136 ;; 1137 esac 1138 } 1139 1140 _docker_container_pause() { 1141 case "$cur" in 1142 -*) 1143 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1144 ;; 1145 *) 1146 __docker_complete_containers_running 1147 ;; 1148 esac 1149 } 1150 1151 _docker_container_port() { 1152 case "$cur" in 1153 -*) 1154 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1155 ;; 1156 *) 1157 local counter=$(__docker_pos_first_nonflag) 1158 if [ $cword -eq $counter ]; then 1159 __docker_complete_containers_all 1160 fi 1161 ;; 1162 esac 1163 } 1164 1165 # TODO new command 1166 _docker_container_prune() { 1167 : 1168 } 1169 1170 _docker_container_ps() { 1171 _docker_container_ls 1172 } 1173 1174 _docker_container_rename() { 1175 case "$cur" in 1176 -*) 1177 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1178 ;; 1179 *) 1180 local counter=$(__docker_pos_first_nonflag) 1181 if [ $cword -eq $counter ]; then 1182 __docker_complete_containers_all 1183 fi 1184 ;; 1185 esac 1186 } 1187 1188 _docker_container_restart() { 1189 case "$prev" in 1190 --time|-t) 1191 return 1192 ;; 1193 esac 1194 1195 case "$cur" in 1196 -*) 1197 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1198 ;; 1199 *) 1200 __docker_complete_containers_all 1201 ;; 1202 esac 1203 } 1204 1205 _docker_container_rm() { 1206 case "$cur" in 1207 -*) 1208 COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) 1209 ;; 1210 *) 1211 for arg in "${COMP_WORDS[@]}"; do 1212 case "$arg" in 1213 --force|-f) 1214 __docker_complete_containers_all 1215 return 1216 ;; 1217 esac 1218 done 1219 __docker_complete_containers_stopped 1220 ;; 1221 esac 1222 } 1223 1224 _docker_container_run() { 1225 local options_with_args=" 1226 --add-host 1227 --attach -a 1228 --blkio-weight 1229 --blkio-weight-device 1230 --cap-add 1231 --cap-drop 1232 --cgroup-parent 1233 --cidfile 1234 --cpu-period 1235 --cpu-quota 1236 --cpu-rt-period 1237 --cpu-rt-runtime 1238 --cpuset-cpus 1239 --cpuset-mems 1240 --cpu-shares -c 1241 --device 1242 --device-read-bps 1243 --device-read-iops 1244 --device-write-bps 1245 --device-write-iops 1246 --dns 1247 --dns-opt 1248 --dns-search 1249 --entrypoint 1250 --env -e 1251 --env-file 1252 --expose 1253 --group-add 1254 --hostname -h 1255 --ip 1256 --ip6 1257 --ipc 1258 --isolation 1259 --kernel-memory 1260 --label-file 1261 --label -l 1262 --link 1263 --link-local-ip 1264 --log-driver 1265 --log-opt 1266 --mac-address 1267 --memory -m 1268 --memory-swap 1269 --memory-swappiness 1270 --memory-reservation 1271 --name 1272 --network 1273 --network-alias 1274 --oom-score-adj 1275 --pid 1276 --pids-limit 1277 --publish -p 1278 --restart 1279 --runtime 1280 --security-opt 1281 --shm-size 1282 --stop-signal 1283 --stop-timeout 1284 --storage-opt 1285 --tmpfs 1286 --sysctl 1287 --ulimit 1288 --user -u 1289 --userns 1290 --uts 1291 --volume-driver 1292 --volumes-from 1293 --volume -v 1294 --workdir -w 1295 " 1296 1297 local boolean_options=" 1298 --disable-content-trust=false 1299 --help 1300 --interactive -i 1301 --oom-kill-disable 1302 --privileged 1303 --publish-all -P 1304 --read-only 1305 --tty -t 1306 " 1307 1308 if [ "$command" = "run" -o "$subcommand" = "run" ] ; then 1309 options_with_args="$options_with_args 1310 --detach-keys 1311 --health-cmd 1312 --health-interval 1313 --health-retries 1314 --health-timeout 1315 " 1316 boolean_options="$boolean_options 1317 --detach -d 1318 --no-healthcheck 1319 --rm 1320 --sig-proxy=false 1321 " 1322 __docker_complete_detach-keys && return 1323 fi 1324 1325 local all_options="$options_with_args $boolean_options" 1326 1327 1328 __docker_complete_log_driver_options && return 1329 __docker_complete_restart && return 1330 1331 local key=$(__docker_map_key_of_current_option '--security-opt') 1332 case "$key" in 1333 label) 1334 [[ $cur == *: ]] && return 1335 COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") ) 1336 if [ "${COMPREPLY[*]}" != "disable" ] ; then 1337 __docker_nospace 1338 fi 1339 return 1340 ;; 1341 seccomp) 1342 local cur=${cur##*=} 1343 _filedir 1344 COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) ) 1345 return 1346 ;; 1347 esac 1348 1349 case "$prev" in 1350 --add-host) 1351 case "$cur" in 1352 *:) 1353 __docker_complete_resolved_hostname 1354 return 1355 ;; 1356 esac 1357 ;; 1358 --attach|-a) 1359 COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) 1360 return 1361 ;; 1362 --cap-add|--cap-drop) 1363 __docker_complete_capabilities 1364 return 1365 ;; 1366 --cidfile|--env-file|--label-file) 1367 _filedir 1368 return 1369 ;; 1370 --device|--tmpfs|--volume|-v) 1371 case "$cur" in 1372 *:*) 1373 # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 1374 ;; 1375 '') 1376 COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) 1377 __docker_nospace 1378 ;; 1379 /*) 1380 _filedir 1381 __docker_nospace 1382 ;; 1383 esac 1384 return 1385 ;; 1386 --env|-e) 1387 # we do not append a "=" here because "-e VARNAME" is legal systax, too 1388 COMPREPLY=( $( compgen -e -- "$cur" ) ) 1389 __docker_nospace 1390 return 1391 ;; 1392 --ipc) 1393 case "$cur" in 1394 *:*) 1395 cur="${cur#*:}" 1396 __docker_complete_containers_running 1397 ;; 1398 *) 1399 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 1400 if [ "$COMPREPLY" = "container:" ]; then 1401 __docker_nospace 1402 fi 1403 ;; 1404 esac 1405 return 1406 ;; 1407 --isolation) 1408 __docker_complete_isolation 1409 return 1410 ;; 1411 --link) 1412 case "$cur" in 1413 *:*) 1414 ;; 1415 *) 1416 __docker_complete_containers_running 1417 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 1418 __docker_nospace 1419 ;; 1420 esac 1421 return 1422 ;; 1423 --log-driver) 1424 __docker_complete_log_drivers 1425 return 1426 ;; 1427 --log-opt) 1428 __docker_complete_log_options 1429 return 1430 ;; 1431 --network) 1432 case "$cur" in 1433 container:*) 1434 __docker_complete_containers_all --cur "${cur#*:}" 1435 ;; 1436 *) 1437 COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") ) 1438 if [ "${COMPREPLY[*]}" = "container:" ] ; then 1439 __docker_nospace 1440 fi 1441 ;; 1442 esac 1443 return 1444 ;; 1445 --pid) 1446 case "$cur" in 1447 *:*) 1448 __docker_complete_containers_running --cur "${cur#*:}" 1449 ;; 1450 *) 1451 COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) 1452 if [ "$COMPREPLY" = "container:" ]; then 1453 __docker_nospace 1454 fi 1455 ;; 1456 esac 1457 return 1458 ;; 1459 --runtime) 1460 __docker_complete_runtimes 1461 return 1462 ;; 1463 --security-opt) 1464 COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") ) 1465 if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then 1466 __docker_nospace 1467 fi 1468 return 1469 ;; 1470 --storage-opt) 1471 COMPREPLY=( $( compgen -W "size" -S = -- "$cur") ) 1472 __docker_nospace 1473 return 1474 ;; 1475 --user|-u) 1476 __docker_complete_user_group 1477 return 1478 ;; 1479 --userns) 1480 COMPREPLY=( $( compgen -W "host" -- "$cur" ) ) 1481 return 1482 ;; 1483 --volume-driver) 1484 __docker_complete_plugins --type Volume 1485 return 1486 ;; 1487 --volumes-from) 1488 __docker_complete_containers_all 1489 return 1490 ;; 1491 $(__docker_to_extglob "$options_with_args") ) 1492 return 1493 ;; 1494 esac 1495 1496 case "$cur" in 1497 -*) 1498 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 1499 ;; 1500 *) 1501 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 1502 if [ $cword -eq $counter ]; then 1503 __docker_complete_images 1504 fi 1505 ;; 1506 esac 1507 } 1508 1509 _docker_container_start() { 1510 __docker_complete_detach-keys && return 1511 1512 case "$cur" in 1513 -*) 1514 COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) ) 1515 ;; 1516 *) 1517 __docker_complete_containers_stopped 1518 ;; 1519 esac 1520 } 1521 1522 _docker_container_stats() { 1523 case "$prev" in 1524 --format) 1525 return 1526 ;; 1527 esac 1528 1529 case "$cur" in 1530 -*) 1531 COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) ) 1532 ;; 1533 *) 1534 __docker_complete_containers_running 1535 ;; 1536 esac 1537 } 1538 1539 _docker_container_stop() { 1540 case "$prev" in 1541 --time|-t) 1542 return 1543 ;; 1544 esac 1545 1546 case "$cur" in 1547 -*) 1548 COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) 1549 ;; 1550 *) 1551 __docker_complete_containers_running 1552 ;; 1553 esac 1554 } 1555 1556 _docker_container_top() { 1557 case "$cur" in 1558 -*) 1559 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1560 ;; 1561 *) 1562 local counter=$(__docker_pos_first_nonflag) 1563 if [ $cword -eq $counter ]; then 1564 __docker_complete_containers_running 1565 fi 1566 ;; 1567 esac 1568 } 1569 1570 _docker_container_unpause() { 1571 case "$cur" in 1572 -*) 1573 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1574 ;; 1575 *) 1576 local counter=$(__docker_pos_first_nonflag) 1577 if [ $cword -eq $counter ]; then 1578 __docker_complete_containers_unpauseable 1579 fi 1580 ;; 1581 esac 1582 } 1583 1584 _docker_container_update() { 1585 local options_with_args=" 1586 --blkio-weight 1587 --cpu-period 1588 --cpu-quota 1589 --cpu-rt-period 1590 --cpu-rt-runtime 1591 --cpuset-cpus 1592 --cpuset-mems 1593 --cpu-shares -c 1594 --kernel-memory 1595 --memory -m 1596 --memory-reservation 1597 --memory-swap 1598 --restart 1599 " 1600 1601 local boolean_options=" 1602 --help 1603 " 1604 1605 local all_options="$options_with_args $boolean_options" 1606 1607 __docker_complete_restart && return 1608 1609 case "$prev" in 1610 $(__docker_to_extglob "$options_with_args") ) 1611 return 1612 ;; 1613 esac 1614 1615 case "$cur" in 1616 -*) 1617 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 1618 ;; 1619 *) 1620 __docker_complete_containers_all 1621 ;; 1622 esac 1623 } 1624 1625 _docker_container_wait() { 1626 case "$cur" in 1627 -*) 1628 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1629 ;; 1630 *) 1631 __docker_complete_containers_all 1632 ;; 1633 esac 1634 } 1635 1636 1637 _docker_commit() { 1638 _docker_container_commit 1639 } 1640 1641 _docker_cp() { 1642 _docker_container_cp 1643 } 1644 1645 _docker_create() { 1646 _docker_container_run 1647 } 1648 1649 _docker_daemon() { 1650 local boolean_options=" 1651 $global_boolean_options 1652 --disable-legacy-registry 1653 --experimental 1654 --help 1655 --icc=false 1656 --ip-forward=false 1657 --ip-masq=false 1658 --iptables=false 1659 --ipv6 1660 --live-restore 1661 --raw-logs 1662 --selinux-enabled 1663 --userland-proxy=false 1664 " 1665 local options_with_args=" 1666 $global_options_with_args 1667 --add-runtime 1668 --api-cors-header 1669 --authorization-plugin 1670 --bip 1671 --bridge -b 1672 --cgroup-parent 1673 --cluster-advertise 1674 --cluster-store 1675 --cluster-store-opt 1676 --config-file 1677 --containerd 1678 --default-gateway 1679 --default-gateway-v6 1680 --default-ulimit 1681 --dns 1682 --dns-search 1683 --dns-opt 1684 --exec-opt 1685 --exec-root 1686 --fixed-cidr 1687 --fixed-cidr-v6 1688 --graph -g 1689 --group -G 1690 --init-path 1691 --insecure-registry 1692 --ip 1693 --label 1694 --log-driver 1695 --log-opt 1696 --max-concurrent-downloads 1697 --max-concurrent-uploads 1698 --mtu 1699 --oom-score-adjust 1700 --pidfile -p 1701 --registry-mirror 1702 --shutdown-timeout 1703 --storage-driver -s 1704 --storage-opt 1705 --userns-remap 1706 " 1707 1708 __docker_complete_log_driver_options && return 1709 1710 key=$(__docker_map_key_of_current_option '--cluster-store-opt') 1711 case "$key" in 1712 kv.*file) 1713 cur=${cur##*=} 1714 _filedir 1715 return 1716 ;; 1717 esac 1718 1719 local key=$(__docker_map_key_of_current_option '--storage-opt') 1720 case "$key" in 1721 dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion) 1722 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 1723 return 1724 ;; 1725 dm.fs) 1726 COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) ) 1727 return 1728 ;; 1729 dm.thinpooldev) 1730 cur=${cur##*=} 1731 _filedir 1732 return 1733 ;; 1734 esac 1735 1736 case "$prev" in 1737 --authorization-plugin) 1738 __docker_complete_plugins --type Authorization 1739 return 1740 ;; 1741 --cluster-store) 1742 COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) ) 1743 __docker_nospace 1744 return 1745 ;; 1746 --cluster-store-opt) 1747 COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) ) 1748 __docker_nospace 1749 return 1750 ;; 1751 --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey) 1752 _filedir 1753 return 1754 ;; 1755 --exec-root|--graph|-g) 1756 _filedir -d 1757 return 1758 ;; 1759 --log-driver) 1760 __docker_complete_log_drivers 1761 return 1762 ;; 1763 --storage-driver|-s) 1764 COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) 1765 return 1766 ;; 1767 --storage-opt) 1768 local btrfs_options="btrfs.min_space" 1769 local devicemapper_options=" 1770 dm.basesize 1771 dm.blkdiscard 1772 dm.blocksize 1773 dm.fs 1774 dm.loopdatasize 1775 dm.loopmetadatasize 1776 dm.min_free_space 1777 dm.mkfsarg 1778 dm.mountopt 1779 dm.override_udev_sync_check 1780 dm.thinpooldev 1781 dm.use_deferred_deletion 1782 dm.use_deferred_removal 1783 " 1784 local zfs_options="zfs.fsname" 1785 1786 case $(__docker_value_of_option '--storage-driver|-s') in 1787 '') 1788 COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) ) 1789 ;; 1790 btrfs) 1791 COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) ) 1792 ;; 1793 devicemapper) 1794 COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) ) 1795 ;; 1796 zfs) 1797 COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) ) 1798 ;; 1799 *) 1800 return 1801 ;; 1802 esac 1803 __docker_nospace 1804 return 1805 ;; 1806 --log-level|-l) 1807 __docker_complete_log_levels 1808 return 1809 ;; 1810 --log-opt) 1811 __docker_complete_log_options 1812 return 1813 ;; 1814 --userns-remap) 1815 __docker_complete_user_group 1816 return 1817 ;; 1818 $(__docker_to_extglob "$options_with_args") ) 1819 return 1820 ;; 1821 esac 1822 1823 case "$cur" in 1824 -*) 1825 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 1826 ;; 1827 esac 1828 } 1829 1830 _docker_diff() { 1831 _docker_container_diff 1832 } 1833 1834 _docker_events() { 1835 _docker_system_events 1836 } 1837 1838 _docker_exec() { 1839 _docker_container_exec 1840 } 1841 1842 _docker_export() { 1843 _docker_container_export 1844 } 1845 1846 _docker_help() { 1847 local counter=$(__docker_pos_first_nonflag) 1848 if [ $cword -eq $counter ]; then 1849 COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) 1850 fi 1851 } 1852 1853 _docker_history() { 1854 _docker_image_history 1855 } 1856 1857 1858 _docker_image() { 1859 local subcommands=" 1860 build 1861 history 1862 import 1863 inspect 1864 load 1865 ls 1866 prune 1867 pull 1868 push 1869 rm 1870 save 1871 tag 1872 " 1873 local aliases=" 1874 images 1875 list 1876 remove 1877 rmi 1878 " 1879 __docker_subcommands "$subcommands $aliases" && return 1880 1881 case "$cur" in 1882 -*) 1883 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 1884 ;; 1885 *) 1886 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 1887 ;; 1888 esac 1889 } 1890 1891 _docker_image_build() { 1892 local options_with_args=" 1893 --build-arg 1894 --cgroup-parent 1895 --cpuset-cpus 1896 --cpuset-mems 1897 --cpu-shares -c 1898 --cpu-period 1899 --cpu-quota 1900 --file -f 1901 --isolation 1902 --label 1903 --memory -m 1904 --memory-swap 1905 --shm-size 1906 --tag -t 1907 --ulimit 1908 " 1909 1910 local boolean_options=" 1911 --compress 1912 --disable-content-trust=false 1913 --force-rm 1914 --help 1915 --no-cache 1916 --pull 1917 --quiet -q 1918 --rm 1919 " 1920 1921 local all_options="$options_with_args $boolean_options" 1922 1923 case "$prev" in 1924 --build-arg) 1925 COMPREPLY=( $( compgen -e -- "$cur" ) ) 1926 __docker_nospace 1927 return 1928 ;; 1929 --file|-f) 1930 _filedir 1931 return 1932 ;; 1933 --isolation) 1934 __docker_complete_isolation 1935 return 1936 ;; 1937 --tag|-t) 1938 __docker_complete_image_repos_and_tags 1939 return 1940 ;; 1941 $(__docker_to_extglob "$options_with_args") ) 1942 return 1943 ;; 1944 esac 1945 1946 case "$cur" in 1947 -*) 1948 COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) 1949 ;; 1950 *) 1951 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 1952 if [ $cword -eq $counter ]; then 1953 _filedir -d 1954 fi 1955 ;; 1956 esac 1957 } 1958 1959 _docker_image_history() { 1960 case "$cur" in 1961 -*) 1962 COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) ) 1963 ;; 1964 *) 1965 local counter=$(__docker_pos_first_nonflag) 1966 if [ $cword -eq $counter ]; then 1967 __docker_complete_images 1968 fi 1969 ;; 1970 esac 1971 } 1972 1973 _docker_image_images() { 1974 _docker_image_ls 1975 } 1976 1977 _docker_image_import() { 1978 case "$prev" in 1979 --change|-c|--message|-m) 1980 return 1981 ;; 1982 esac 1983 1984 case "$cur" in 1985 -*) 1986 COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) ) 1987 ;; 1988 *) 1989 local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m') 1990 if [ $cword -eq $counter ]; then 1991 return 1992 fi 1993 (( counter++ )) 1994 1995 if [ $cword -eq $counter ]; then 1996 __docker_complete_image_repos_and_tags 1997 return 1998 fi 1999 ;; 2000 esac 2001 } 2002 2003 _docker_image_inspect() { 2004 _docker_inspect --type image 2005 } 2006 2007 _docker_image_load() { 2008 case "$prev" in 2009 --input|-i) 2010 _filedir 2011 return 2012 ;; 2013 esac 2014 2015 case "$cur" in 2016 -*) 2017 COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) ) 2018 ;; 2019 esac 2020 } 2021 2022 _docker_image_list() { 2023 _docker_image_ls 2024 } 2025 2026 _docker_image_ls() { 2027 local key=$(__docker_map_key_of_current_option '--filter|-f') 2028 case "$key" in 2029 before) 2030 cur="${cur##*=}" 2031 __docker_complete_images 2032 return 2033 ;; 2034 dangling) 2035 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 2036 return 2037 ;; 2038 label) 2039 return 2040 ;; 2041 since) 2042 cur="${cur##*=}" 2043 __docker_complete_images 2044 return 2045 ;; 2046 esac 2047 2048 case "$prev" in 2049 --filter|-f) 2050 COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) ) 2051 __docker_nospace 2052 return 2053 ;; 2054 --format) 2055 return 2056 ;; 2057 esac 2058 2059 case "$cur" in 2060 -*) 2061 COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) 2062 ;; 2063 =) 2064 return 2065 ;; 2066 *) 2067 __docker_complete_image_repos 2068 ;; 2069 esac 2070 } 2071 2072 # TODO new command 2073 _docker_image_prune() { 2074 : 2075 } 2076 2077 _docker_image_pull() { 2078 case "$cur" in 2079 -*) 2080 COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) ) 2081 ;; 2082 *) 2083 local counter=$(__docker_pos_first_nonflag) 2084 if [ $cword -eq $counter ]; then 2085 for arg in "${COMP_WORDS[@]}"; do 2086 case "$arg" in 2087 --all-tags|-a) 2088 __docker_complete_image_repos 2089 return 2090 ;; 2091 esac 2092 done 2093 __docker_complete_image_repos_and_tags 2094 fi 2095 ;; 2096 esac 2097 } 2098 2099 _docker_image_push() { 2100 case "$cur" in 2101 -*) 2102 COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) ) 2103 ;; 2104 *) 2105 local counter=$(__docker_pos_first_nonflag) 2106 if [ $cword -eq $counter ]; then 2107 __docker_complete_image_repos_and_tags 2108 fi 2109 ;; 2110 esac 2111 } 2112 2113 _docker_image_remove() { 2114 _docker_image_rm 2115 } 2116 2117 _docker_image_rm() { 2118 case "$cur" in 2119 -*) 2120 COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) 2121 ;; 2122 *) 2123 __docker_complete_images 2124 ;; 2125 esac 2126 } 2127 2128 _docker_image_rmi() { 2129 _docker_image_rm 2130 } 2131 2132 _docker_image_save() { 2133 case "$prev" in 2134 --output|-o) 2135 _filedir 2136 return 2137 ;; 2138 esac 2139 2140 case "$cur" in 2141 -*) 2142 COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) 2143 ;; 2144 *) 2145 __docker_complete_images 2146 ;; 2147 esac 2148 } 2149 2150 _docker_image_tag() { 2151 case "$cur" in 2152 -*) 2153 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2154 ;; 2155 *) 2156 local counter=$(__docker_pos_first_nonflag) 2157 2158 if [ $cword -eq $counter ]; then 2159 __docker_complete_image_repos_and_tags 2160 return 2161 fi 2162 (( counter++ )) 2163 2164 if [ $cword -eq $counter ]; then 2165 __docker_complete_image_repos_and_tags 2166 return 2167 fi 2168 ;; 2169 esac 2170 } 2171 2172 2173 _docker_images() { 2174 _docker_image_ls 2175 } 2176 2177 _docker_import() { 2178 _docker_image_import 2179 } 2180 2181 _docker_info() { 2182 _docker_system_info 2183 } 2184 2185 _docker_inspect() { 2186 local type 2187 2188 if [ "$1" = "--type" ] ; then 2189 type="$2" 2190 else 2191 type=$(__docker_value_of_option --type) 2192 fi 2193 2194 case "$prev" in 2195 --format|-f) 2196 return 2197 ;; 2198 --type) 2199 if [ -z "$type" ] ; then 2200 COMPREPLY=( $( compgen -W "image container" -- "$cur" ) ) 2201 fi 2202 return 2203 ;; 2204 esac 2205 2206 case "$cur" in 2207 -*) 2208 local options="--format -f --help --size -s" 2209 if [ -z "$type" ] ; then 2210 options+=" --type" 2211 fi 2212 COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) 2213 ;; 2214 *) 2215 case "$type" in 2216 '') 2217 __docker_complete_containers_and_images 2218 ;; 2219 container) 2220 __docker_complete_containers_all 2221 ;; 2222 image) 2223 __docker_complete_images 2224 ;; 2225 esac 2226 esac 2227 } 2228 2229 _docker_kill() { 2230 _docker_container_kill 2231 } 2232 2233 _docker_load() { 2234 _docker_image_load 2235 } 2236 2237 _docker_login() { 2238 case "$prev" in 2239 --password|-p|--username|-u) 2240 return 2241 ;; 2242 esac 2243 2244 case "$cur" in 2245 -*) 2246 COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) ) 2247 ;; 2248 esac 2249 } 2250 2251 _docker_logout() { 2252 case "$cur" in 2253 -*) 2254 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2255 ;; 2256 esac 2257 } 2258 2259 _docker_logs() { 2260 _docker_container_logs 2261 } 2262 2263 _docker_network_connect() { 2264 local options_with_args=" 2265 --alias 2266 --ip 2267 --ip6 2268 --link 2269 --link-local-ip 2270 " 2271 2272 local boolean_options=" 2273 --help 2274 " 2275 2276 case "$prev" in 2277 --link) 2278 case "$cur" in 2279 *:*) 2280 ;; 2281 *) 2282 __docker_complete_containers_running 2283 COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) 2284 __docker_nospace 2285 ;; 2286 esac 2287 return 2288 ;; 2289 $(__docker_to_extglob "$options_with_args") ) 2290 return 2291 ;; 2292 esac 2293 2294 case "$cur" in 2295 -*) 2296 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 2297 ;; 2298 *) 2299 local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) 2300 if [ $cword -eq $counter ]; then 2301 __docker_complete_networks 2302 elif [ $cword -eq $(($counter + 1)) ]; then 2303 __docker_complete_containers_all 2304 fi 2305 ;; 2306 esac 2307 } 2308 2309 _docker_network_create() { 2310 case "$prev" in 2311 --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet) 2312 return 2313 ;; 2314 --ipam-driver) 2315 COMPREPLY=( $( compgen -W "default" -- "$cur" ) ) 2316 return 2317 ;; 2318 --driver|-d) 2319 # remove drivers that allow one instance only, add drivers missing in `docker info` 2320 __docker_complete_plugins --type Network --remove host --remove null --add macvlan 2321 return 2322 ;; 2323 --label) 2324 return 2325 ;; 2326 esac 2327 2328 case "$cur" in 2329 -*) 2330 COMPREPLY=( $( compgen -W "--aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) ) 2331 ;; 2332 esac 2333 } 2334 2335 _docker_network_disconnect() { 2336 case "$cur" in 2337 -*) 2338 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2339 ;; 2340 *) 2341 local counter=$(__docker_pos_first_nonflag) 2342 if [ $cword -eq $counter ]; then 2343 __docker_complete_networks 2344 elif [ $cword -eq $(($counter + 1)) ]; then 2345 __docker_complete_containers_in_network "$prev" 2346 fi 2347 ;; 2348 esac 2349 } 2350 2351 _docker_network_inspect() { 2352 case "$prev" in 2353 --format|-f) 2354 return 2355 ;; 2356 esac 2357 2358 case "$cur" in 2359 -*) 2360 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 2361 ;; 2362 *) 2363 __docker_complete_networks 2364 esac 2365 } 2366 2367 _docker_network_ls() { 2368 local key=$(__docker_map_key_of_current_option '--filter|-f') 2369 case "$key" in 2370 driver) 2371 __docker_complete_plugins --cur "${cur##*=}" --type Network --add macvlan 2372 return 2373 ;; 2374 id) 2375 __docker_complete_networks --cur "${cur##*=}" --id 2376 return 2377 ;; 2378 name) 2379 __docker_complete_networks --cur "${cur##*=}" --name 2380 return 2381 ;; 2382 type) 2383 COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) ) 2384 return 2385 ;; 2386 esac 2387 2388 case "$prev" in 2389 --filter|-f) 2390 COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) ) 2391 __docker_nospace 2392 return 2393 ;; 2394 --format) 2395 return 2396 ;; 2397 esac 2398 2399 case "$cur" in 2400 -*) 2401 COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) 2402 ;; 2403 esac 2404 } 2405 2406 _docker_network_rm() { 2407 case "$cur" in 2408 -*) 2409 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2410 ;; 2411 *) 2412 __docker_complete_networks --filter type=custom 2413 esac 2414 } 2415 2416 _docker_network() { 2417 local subcommands=" 2418 connect 2419 create 2420 disconnect 2421 inspect 2422 ls 2423 rm 2424 " 2425 __docker_subcommands "$subcommands" && return 2426 2427 case "$cur" in 2428 -*) 2429 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2430 ;; 2431 *) 2432 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2433 ;; 2434 esac 2435 } 2436 2437 _docker_service() { 2438 local subcommands=" 2439 create 2440 inspect 2441 ls list 2442 rm remove 2443 scale 2444 ps 2445 update 2446 " 2447 __docker_subcommands "$subcommands" && return 2448 2449 case "$cur" in 2450 -*) 2451 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2452 ;; 2453 *) 2454 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2455 ;; 2456 esac 2457 } 2458 2459 _docker_service_create() { 2460 _docker_service_update 2461 } 2462 2463 _docker_service_inspect() { 2464 case "$prev" in 2465 --format|-f) 2466 return 2467 ;; 2468 esac 2469 2470 case "$cur" in 2471 -*) 2472 COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) 2473 ;; 2474 *) 2475 __docker_complete_services 2476 esac 2477 } 2478 2479 _docker_service_list() { 2480 _docker_service_ls 2481 } 2482 2483 _docker_service_ls() { 2484 local key=$(__docker_map_key_of_current_option '--filter|-f') 2485 case "$key" in 2486 id) 2487 __docker_complete_services --cur "${cur##*=}" --id 2488 return 2489 ;; 2490 name) 2491 __docker_complete_services --cur "${cur##*=}" --name 2492 return 2493 ;; 2494 esac 2495 2496 case "$prev" in 2497 --filter|-f) 2498 COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) 2499 __docker_nospace 2500 return 2501 ;; 2502 esac 2503 2504 case "$cur" in 2505 -*) 2506 COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) 2507 ;; 2508 esac 2509 } 2510 2511 _docker_service_remove() { 2512 _docker_service_rm 2513 } 2514 2515 _docker_service_rm() { 2516 case "$cur" in 2517 -*) 2518 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2519 ;; 2520 *) 2521 __docker_complete_services 2522 esac 2523 } 2524 2525 _docker_service_scale() { 2526 case "$cur" in 2527 -*) 2528 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2529 ;; 2530 *) 2531 __docker_complete_services 2532 __docker_append_to_completions "=" 2533 __docker_nospace 2534 ;; 2535 esac 2536 } 2537 2538 _docker_service_ps() { 2539 local key=$(__docker_map_key_of_current_option '--filter|-f') 2540 case "$key" in 2541 desired-state) 2542 COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) 2543 return 2544 ;; 2545 name) 2546 __docker_complete_services --cur "${cur##*=}" --name 2547 return 2548 ;; 2549 esac 2550 2551 case "$prev" in 2552 --filter|-f) 2553 COMPREPLY=( $( compgen -W "desired-state id name" -S = -- "$cur" ) ) 2554 __docker_nospace 2555 return 2556 ;; 2557 esac 2558 2559 case "$cur" in 2560 -*) 2561 COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) ) 2562 ;; 2563 *) 2564 local counter=$(__docker_pos_first_nonflag '--filter|-f') 2565 if [ $cword -eq $counter ]; then 2566 __docker_complete_services 2567 fi 2568 ;; 2569 esac 2570 } 2571 2572 _docker_service_update() { 2573 local $subcommand="${words[$subcommand_pos]}" 2574 2575 local options_with_args=" 2576 --constraint 2577 --endpoint-mode 2578 --env -e 2579 --force 2580 --health-cmd 2581 --health-interval 2582 --health-retries 2583 --health-timeout 2584 --label -l 2585 --limit-cpu 2586 --limit-memory 2587 --log-driver 2588 --log-opt 2589 --mount 2590 --network 2591 --no-healthcheck 2592 --publish -p 2593 --replicas 2594 --reserve-cpu 2595 --reserve-memory 2596 --restart-condition 2597 --restart-delay 2598 --restart-max-attempts 2599 --restart-window 2600 --rollback 2601 --stop-grace-period 2602 --update-delay 2603 --update-failure-action 2604 --update-max-failure-ratio 2605 --update-monitor 2606 --update-parallelism 2607 --user -u 2608 --workdir -w 2609 " 2610 2611 local boolean_options=" 2612 --help 2613 --with-registry-auth 2614 " 2615 2616 __docker_complete_log_driver_options && return 2617 2618 if [ "$subcommand" = "create" ] ; then 2619 options_with_args="$options_with_args 2620 --container-label 2621 --env-file 2622 --group 2623 --mode 2624 --name 2625 " 2626 2627 case "$prev" in 2628 --env-file) 2629 _filedir 2630 return 2631 ;; 2632 --mode) 2633 COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) ) 2634 return 2635 ;; 2636 --group) 2637 COMPREPLY=( $(compgen -g -- "$cur") ) 2638 return 2639 ;; 2640 esac 2641 fi 2642 if [ "$subcommand" = "update" ] ; then 2643 options_with_args="$options_with_args 2644 --arg 2645 --container-label-add 2646 --container-label-rm 2647 --group-add 2648 --group-rm 2649 --image 2650 " 2651 2652 case "$prev" in 2653 --group-add) 2654 COMPREPLY=( $(compgen -g -- "$cur") ) 2655 return 2656 ;; 2657 --group-rm) 2658 COMPREPLY=( $(compgen -g -- "$cur") ) 2659 return 2660 ;; 2661 --image) 2662 __docker_complete_image_repos_and_tags 2663 return 2664 ;; 2665 esac 2666 fi 2667 2668 case "$prev" in 2669 --endpoint-mode) 2670 COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) ) 2671 return 2672 ;; 2673 --env|-e) 2674 # we do not append a "=" here because "-e VARNAME" is legal systax, too 2675 COMPREPLY=( $( compgen -e -- "$cur" ) ) 2676 __docker_nospace 2677 return 2678 ;; 2679 --log-driver) 2680 __docker_complete_log_drivers 2681 return 2682 ;; 2683 --log-opt) 2684 __docker_complete_log_options 2685 return 2686 ;; 2687 --network) 2688 __docker_complete_networks 2689 return 2690 ;; 2691 --restart-condition) 2692 COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) ) 2693 return 2694 ;; 2695 --user|-u) 2696 __docker_complete_user_group 2697 return 2698 ;; 2699 $(__docker_to_extglob "$options_with_args") ) 2700 return 2701 ;; 2702 esac 2703 2704 case "$cur" in 2705 -*) 2706 COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) 2707 ;; 2708 *) 2709 if [ "$subcommand" = "update" ] ; then 2710 __docker_complete_services 2711 fi 2712 esac 2713 } 2714 2715 _docker_swarm() { 2716 local subcommands=" 2717 init 2718 join 2719 join-token 2720 leave 2721 update 2722 " 2723 __docker_subcommands "$subcommands" && return 2724 2725 case "$cur" in 2726 -*) 2727 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2728 ;; 2729 *) 2730 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2731 ;; 2732 esac 2733 } 2734 2735 _docker_swarm_init() { 2736 case "$prev" in 2737 --advertise-addr) 2738 if [[ $cur == *: ]] ; then 2739 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2740 else 2741 __docker_complete_local_interfaces 2742 __docker_nospace 2743 fi 2744 return 2745 ;; 2746 --listen-addr) 2747 if [[ $cur == *: ]] ; then 2748 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2749 else 2750 __docker_complete_local_interfaces --add 0.0.0.0 2751 __docker_nospace 2752 fi 2753 return 2754 ;; 2755 esac 2756 2757 case "$cur" in 2758 -*) 2759 COMPREPLY=( $( compgen -W "--advertise-addr --force-new-cluster --help --listen-addr" -- "$cur" ) ) 2760 ;; 2761 esac 2762 } 2763 2764 _docker_swarm_join() { 2765 case "$prev" in 2766 --advertise-addr) 2767 if [[ $cur == *: ]] ; then 2768 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2769 else 2770 __docker_complete_local_interfaces 2771 __docker_nospace 2772 fi 2773 return 2774 ;; 2775 --listen-addr) 2776 if [[ $cur == *: ]] ; then 2777 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2778 else 2779 __docker_complete_local_interfaces --add 0.0.0.0 2780 __docker_nospace 2781 fi 2782 return 2783 ;; 2784 --token) 2785 return 2786 ;; 2787 esac 2788 2789 case "$cur" in 2790 -*) 2791 COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) ) 2792 ;; 2793 *:) 2794 COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) 2795 ;; 2796 esac 2797 } 2798 2799 _docker_swarm_join-token() { 2800 case "$cur" in 2801 -*) 2802 COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) ) 2803 ;; 2804 *) 2805 local counter=$( __docker_pos_first_nonflag ) 2806 if [ $cword -eq $counter ]; then 2807 COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) 2808 fi 2809 ;; 2810 esac 2811 } 2812 2813 _docker_swarm_leave() { 2814 case "$cur" in 2815 -*) 2816 COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) ) 2817 ;; 2818 esac 2819 } 2820 2821 _docker_swarm_update() { 2822 case "$prev" in 2823 --cert-expiry|--dispatcher-heartbeat|--task-history-limit) 2824 return 2825 ;; 2826 esac 2827 2828 case "$cur" in 2829 -*) 2830 COMPREPLY=( $( compgen -W "--cert-expiry --dispatcher-heartbeat --help --task-history-limit" -- "$cur" ) ) 2831 ;; 2832 esac 2833 } 2834 2835 _docker_node() { 2836 local subcommands=" 2837 demote 2838 inspect 2839 ls list 2840 promote 2841 rm remove 2842 ps 2843 update 2844 " 2845 __docker_subcommands "$subcommands" && return 2846 2847 case "$cur" in 2848 -*) 2849 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2850 ;; 2851 *) 2852 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 2853 ;; 2854 esac 2855 } 2856 2857 _docker_node_demote() { 2858 case "$cur" in 2859 -*) 2860 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2861 ;; 2862 *) 2863 __docker_complete_nodes --filter role=manager 2864 esac 2865 } 2866 2867 _docker_node_inspect() { 2868 case "$prev" in 2869 --format|-f) 2870 return 2871 ;; 2872 esac 2873 2874 case "$cur" in 2875 -*) 2876 COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) 2877 ;; 2878 *) 2879 __docker_complete_nodes_plus_self 2880 esac 2881 } 2882 2883 _docker_node_list() { 2884 _docker_node_ls 2885 } 2886 2887 _docker_node_ls() { 2888 local key=$(__docker_map_key_of_current_option '--filter|-f') 2889 case "$key" in 2890 id) 2891 __docker_complete_nodes --cur "${cur##*=}" --id 2892 return 2893 ;; 2894 name) 2895 __docker_complete_nodes --cur "${cur##*=}" --name 2896 return 2897 ;; 2898 esac 2899 2900 case "$prev" in 2901 --filter|-f) 2902 COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) 2903 __docker_nospace 2904 return 2905 ;; 2906 esac 2907 2908 case "$cur" in 2909 -*) 2910 COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) 2911 ;; 2912 esac 2913 } 2914 2915 _docker_node_promote() { 2916 case "$cur" in 2917 -*) 2918 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 2919 ;; 2920 *) 2921 __docker_complete_nodes --filter role=worker 2922 esac 2923 } 2924 2925 _docker_node_remove() { 2926 _docker_node_rm 2927 } 2928 2929 _docker_node_rm() { 2930 case "$cur" in 2931 -*) 2932 COMPREPLY=( $( compgen -W "--force --help" -- "$cur" ) ) 2933 ;; 2934 *) 2935 __docker_complete_nodes 2936 esac 2937 } 2938 2939 _docker_node_ps() { 2940 local key=$(__docker_map_key_of_current_option '--filter|-f') 2941 case "$key" in 2942 desired-state) 2943 COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) 2944 return 2945 ;; 2946 name) 2947 __docker_complete_services --cur "${cur##*=}" --name 2948 return 2949 ;; 2950 esac 2951 2952 case "$prev" in 2953 --filter|-f) 2954 COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) ) 2955 __docker_nospace 2956 return 2957 ;; 2958 esac 2959 2960 case "$cur" in 2961 -*) 2962 COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) ) 2963 ;; 2964 *) 2965 __docker_complete_nodes_plus_self 2966 ;; 2967 esac 2968 } 2969 2970 _docker_node_update() { 2971 case "$prev" in 2972 --availability) 2973 COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) ) 2974 return 2975 ;; 2976 --role) 2977 COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) 2978 return 2979 ;; 2980 --label-add|--label-rm) 2981 return 2982 ;; 2983 esac 2984 2985 case "$cur" in 2986 -*) 2987 COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) ) 2988 ;; 2989 *) 2990 __docker_complete_nodes 2991 esac 2992 } 2993 2994 _docker_pause() { 2995 _docker_container_pause 2996 } 2997 2998 _docker_port() { 2999 _docker_container_port 3000 } 3001 3002 _docker_ps() { 3003 _docker_container_ls 3004 } 3005 3006 _docker_pull() { 3007 _docker_image_pull 3008 } 3009 3010 _docker_push() { 3011 _docker_image_push 3012 } 3013 3014 _docker_rename() { 3015 _docker_container_rename 3016 } 3017 3018 _docker_restart() { 3019 _docker_container_restart 3020 } 3021 3022 _docker_rm() { 3023 _docker_container_rm 3024 } 3025 3026 _docker_rmi() { 3027 _docker_image_rm 3028 } 3029 3030 _docker_run() { 3031 _docker_container_run 3032 } 3033 3034 _docker_save() { 3035 _docker_image_save 3036 } 3037 3038 _docker_search() { 3039 local key=$(__docker_map_key_of_current_option '--filter|-f') 3040 case "$key" in 3041 is-automated) 3042 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 3043 return 3044 ;; 3045 is-official) 3046 COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) 3047 return 3048 ;; 3049 esac 3050 3051 case "$prev" in 3052 --filter|-f) 3053 COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) ) 3054 __docker_nospace 3055 return 3056 ;; 3057 --limit) 3058 return 3059 ;; 3060 esac 3061 3062 case "$cur" in 3063 -*) 3064 COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) ) 3065 ;; 3066 esac 3067 } 3068 3069 _docker_start() { 3070 _docker_container_start 3071 } 3072 3073 _docker_stats() { 3074 _docker_container_stats 3075 } 3076 3077 _docker_stop() { 3078 _docker_container_stop 3079 } 3080 3081 3082 _docker_system() { 3083 local subcommands=" 3084 df 3085 events 3086 info 3087 prune 3088 " 3089 __docker_subcommands "$subcommands $aliases" && return 3090 3091 case "$cur" in 3092 -*) 3093 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 3094 ;; 3095 *) 3096 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 3097 ;; 3098 esac 3099 } 3100 3101 # TODO new command 3102 _docker_system_df() { 3103 : 3104 } 3105 3106 _docker_system_events() { 3107 local key=$(__docker_map_key_of_current_option '-f|--filter') 3108 case "$key" in 3109 container) 3110 __docker_complete_containers_all --cur "${cur##*=}" 3111 return 3112 ;; 3113 daemon) 3114 local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p') 3115 COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) ) 3116 return 3117 ;; 3118 event) 3119 COMPREPLY=( $( compgen -W " 3120 attach 3121 commit 3122 connect 3123 copy 3124 create 3125 delete 3126 destroy 3127 detach 3128 die 3129 disconnect 3130 exec_create 3131 exec_detach 3132 exec_start 3133 export 3134 health_status 3135 import 3136 kill 3137 load 3138 mount 3139 oom 3140 pause 3141 pull 3142 push 3143 reload 3144 rename 3145 resize 3146 restart 3147 save 3148 start 3149 stop 3150 tag 3151 top 3152 unmount 3153 unpause 3154 untag 3155 update 3156 " -- "${cur##*=}" ) ) 3157 return 3158 ;; 3159 image) 3160 cur="${cur##*=}" 3161 __docker_complete_images 3162 return 3163 ;; 3164 network) 3165 __docker_complete_networks --cur "${cur##*=}" 3166 return 3167 ;; 3168 type) 3169 COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) ) 3170 return 3171 ;; 3172 volume) 3173 __docker_complete_volumes --cur "${cur##*=}" 3174 return 3175 ;; 3176 esac 3177 3178 case "$prev" in 3179 --filter|-f) 3180 COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) ) 3181 __docker_nospace 3182 return 3183 ;; 3184 --since|--until) 3185 return 3186 ;; 3187 esac 3188 3189 case "$cur" in 3190 -*) 3191 COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) ) 3192 ;; 3193 esac 3194 } 3195 3196 _docker_system_info() { 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 esac 3208 } 3209 3210 # TODO new command 3211 _docker_system_prune() { 3212 : 3213 } 3214 3215 3216 _docker_tag() { 3217 _docker_image_tag 3218 } 3219 3220 _docker_unpause() { 3221 _docker_container_unpause 3222 } 3223 3224 _docker_update() { 3225 _docker_container_update 3226 } 3227 3228 _docker_top() { 3229 _docker_container_top 3230 } 3231 3232 _docker_version() { 3233 case "$cur" in 3234 -*) 3235 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 3236 ;; 3237 esac 3238 } 3239 3240 _docker_volume_create() { 3241 case "$prev" in 3242 --driver|-d) 3243 __docker_complete_plugins --type Volume 3244 return 3245 ;; 3246 --label|--opt|-o) 3247 return 3248 ;; 3249 esac 3250 3251 case "$cur" in 3252 -*) 3253 COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) ) 3254 ;; 3255 esac 3256 } 3257 3258 _docker_volume_inspect() { 3259 case "$prev" in 3260 --format|-f) 3261 return 3262 ;; 3263 esac 3264 3265 case "$cur" in 3266 -*) 3267 COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) 3268 ;; 3269 *) 3270 __docker_complete_volumes 3271 ;; 3272 esac 3273 } 3274 3275 _docker_volume_ls() { 3276 local key=$(__docker_map_key_of_current_option '--filter|-f') 3277 case "$key" in 3278 dangling) 3279 COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) 3280 return 3281 ;; 3282 driver) 3283 __docker_complete_plugins --cur "${cur##*=}" --type Volume 3284 return 3285 ;; 3286 name) 3287 __docker_complete_volumes --cur "${cur##*=}" 3288 return 3289 ;; 3290 esac 3291 3292 case "$prev" in 3293 --filter|-f) 3294 COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) ) 3295 __docker_nospace 3296 return 3297 ;; 3298 --format) 3299 return 3300 ;; 3301 esac 3302 3303 case "$cur" in 3304 -*) 3305 COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) ) 3306 ;; 3307 esac 3308 } 3309 3310 _docker_volume_rm() { 3311 case "$cur" in 3312 -*) 3313 COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) 3314 ;; 3315 *) 3316 __docker_complete_volumes 3317 ;; 3318 esac 3319 } 3320 3321 _docker_volume() { 3322 local subcommands=" 3323 create 3324 inspect 3325 ls 3326 rm 3327 " 3328 __docker_subcommands "$subcommands" && return 3329 3330 case "$cur" in 3331 -*) 3332 COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) 3333 ;; 3334 *) 3335 COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) 3336 ;; 3337 esac 3338 } 3339 3340 _docker_wait() { 3341 _docker_container_wait 3342 } 3343 3344 _docker() { 3345 local previous_extglob_setting=$(shopt -p extglob) 3346 shopt -s extglob 3347 3348 local commands=( 3349 attach 3350 build 3351 commit 3352 container 3353 cp 3354 create 3355 daemon 3356 diff 3357 events 3358 exec 3359 export 3360 history 3361 image 3362 images 3363 import 3364 info 3365 inspect 3366 kill 3367 load 3368 login 3369 logout 3370 logs 3371 network 3372 node 3373 pause 3374 port 3375 ps 3376 pull 3377 push 3378 rename 3379 restart 3380 rm 3381 rmi 3382 run 3383 save 3384 search 3385 service 3386 start 3387 stats 3388 stop 3389 swarm 3390 system 3391 tag 3392 top 3393 unpause 3394 update 3395 version 3396 volume 3397 wait 3398 ) 3399 3400 # These options are valid as global options for all client commands 3401 # and valid as command options for `docker daemon` 3402 local global_boolean_options=" 3403 --debug -D 3404 --tls 3405 --tlsverify 3406 " 3407 local global_options_with_args=" 3408 --config 3409 --host -H 3410 --log-level -l 3411 --tlscacert 3412 --tlscert 3413 --tlskey 3414 " 3415 3416 local host config 3417 3418 COMPREPLY=() 3419 local cur prev words cword 3420 _get_comp_words_by_ref -n : cur prev words cword 3421 3422 local command='docker' command_pos=0 subcommand_pos 3423 local counter=1 3424 while [ $counter -lt $cword ]; do 3425 case "${words[$counter]}" in 3426 # save host so that completion can use custom daemon 3427 --host|-H) 3428 (( counter++ )) 3429 host="${words[$counter]}" 3430 ;; 3431 # save config so that completion can use custom configuration directories 3432 --config) 3433 (( counter++ )) 3434 config="${words[$counter]}" 3435 ;; 3436 $(__docker_to_extglob "$global_options_with_args") ) 3437 (( counter++ )) 3438 ;; 3439 -*) 3440 ;; 3441 =) 3442 (( counter++ )) 3443 ;; 3444 *) 3445 command="${words[$counter]}" 3446 command_pos=$counter 3447 break 3448 ;; 3449 esac 3450 (( counter++ )) 3451 done 3452 3453 local binary="${words[0]}" 3454 if [[ $binary == ?(*/)dockerd ]] ; then 3455 # for the dockerd binary, we reuse completion of `docker daemon`. 3456 # dockerd does not have subcommands and global options. 3457 command=daemon 3458 command_pos=0 3459 fi 3460 3461 local completions_func=_docker_${command} 3462 declare -F $completions_func >/dev/null && $completions_func 3463 3464 eval "$previous_extglob_setting" 3465 return 0 3466 } 3467 3468 eval "$__docker_previous_extglob_setting" 3469 unset __docker_previous_extglob_setting 3470 3471 complete -F _docker docker dockerd