github.com/ali-iotechsys/cli@v20.10.0+incompatible/contrib/completion/bash/docker (about)

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