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