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