github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/contrib/completion/bash/docker (about)

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