github.com/xeptore/docker-cli@v20.10.14+incompatible/contrib/completion/bash/docker (about)

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