github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/contrib/completion/bash/docker (about)

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