Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #135 from thaJeztah/completion-cherry-picks
Browse files Browse the repository at this point in the history
[17.06] Completion cherry picks
  • Loading branch information
andrewhsu authored Jul 26, 2017
2 parents b0019a4 + 114d979 commit eb669c3
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 23 deletions.
181 changes: 171 additions & 10 deletions components/cli/contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# For several commands, the amount of completions can be configured by
# setting environment variables.
#
# DOCKER_COMPLETION_SHOW_CONFIG_IDS
# DOCKER_COMPLETION_SHOW_CONTAINER_IDS
# DOCKER_COMPLETION_SHOW_NETWORK_IDS
# DOCKER_COMPLETION_SHOW_NODE_IDS
Expand Down Expand Up @@ -61,6 +62,42 @@ __docker_q() {
docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@"
}

# __docker_configs returns a list of configs. Additional options to
# `docker config ls` may be specified in order to filter the list, e.g.
# `__docker_configs --filter label=stage=production`.
# By default, only names are returned.
# Set DOCKER_COMPLETION_SHOW_CONFIG_IDS=yes to also complete IDs.
# An optional first option `--id|--name` may be used to limit the
# output to the IDs or names of matching items. This setting takes
# precedence over the environment setting.
__docker_configs() {
local format
if [ "$1" = "--id" ] ; then
format='{{.ID}}'
shift
elif [ "$1" = "--name" ] ; then
format='{{.Name}}'
shift
elif [ "$DOCKER_COMPLETION_SHOW_CONFIG_IDS" = yes ] ; then
format='{{.ID}} {{.Name}}'
else
format='{{.Name}}'
fi

__docker_q config ls --format "$format" "$@"
}

# __docker_complete_configs applies completion of configs based on the current value
# of `$cur` or the value of the optional first option `--cur`, if given.
__docker_complete_configs() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
current="$2"
shift 2
fi
COMPREPLY=( $(compgen -W "$(__docker_configs "$@")" -- "$current") )
}

# __docker_containers returns a list of containers. Additional options to
# `docker ps` may be specified in order to filter the list, e.g.
# `__docker_containers --filter status=running`
Expand Down Expand Up @@ -754,7 +791,7 @@ __docker_complete_log_options() {
local common_options2="env env-regex labels"

# awslogs does not implement the $common_options2.
local awslogs_options="$common_options1 awslogs-create-group awslogs-group awslogs-region awslogs-stream tag"
local awslogs_options="$common_options1 awslogs-create-group awslogs-datetime-format awslogs-group awslogs-multiline-pattern awslogs-region awslogs-stream tag"

local fluentd_options="$common_options1 $common_options2 fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries tag"
local gcplogs_options="$common_options1 $common_options2 gcp-log-cmd gcp-meta-id gcp-meta-name gcp-meta-zone gcp-project"
Expand Down Expand Up @@ -1074,6 +1111,117 @@ _docker_checkpoint_rm() {
}


_docker_config() {
local subcommands="
create
inspect
ls
rm
"
local aliases="
list
remove
"
__docker_subcommands "$subcommands $aliases" && return

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
;;
esac
}

_docker_config_create() {
case "$prev" in
--label|-l)
return
;;
esac

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --label -l" -- "$cur" ) )
;;
*)
local counter=$(__docker_pos_first_nonflag '--label|-l')
if [ $cword -eq $((counter + 1)) ]; then
_filedir
fi
;;
esac
}

_docker_config_inspect() {
case "$prev" in
--format|-f)
return
;;
esac

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
;;
*)
__docker_complete_configs
;;
esac
}

_docker_config_list() {
_docker_config_ls
}

_docker_config_ls() {
local key=$(__docker_map_key_of_current_option '--filter|-f')
case "$key" in
id)
__docker_complete_configs --cur "${cur##*=}" --id
return
;;
name)
__docker_complete_configs --cur "${cur##*=}" --name
return
;;
esac

case "$prev" in
--filter|-f)
COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
__docker_nospace
return
;;
--format)
return
;;
esac

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--format --filter -f --help --quiet -q" -- "$cur" ) )
;;
esac
}

_docker_config_remove() {
_docker_config_rm
}

_docker_config_rm() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_complete_configs
;;
esac
}


_docker_container() {
local subcommands="
attach
Expand Down Expand Up @@ -2221,6 +2369,7 @@ _docker_image_build() {
--cpu-period
--cpu-quota
--file -f
--iidfile
--label
--memory -m
--memory-swap
Expand Down Expand Up @@ -2265,7 +2414,7 @@ _docker_image_build() {
__docker_complete_image_repos_and_tags
return
;;
--file|-f)
--file|-f|--iidfile)
_filedir
return
;;
Expand Down Expand Up @@ -3088,7 +3237,7 @@ _docker_service_update_and_create() {
"

local boolean_options="
--detach -d
--detach=false -d=false
--help
--no-healthcheck
--read-only
Expand All @@ -3100,6 +3249,7 @@ _docker_service_update_and_create() {

if [ "$subcommand" = "create" ] ; then
options_with_args="$options_with_args
--config
--constraint
--container-label
--dns
Expand All @@ -3117,6 +3267,10 @@ _docker_service_update_and_create() {
"

case "$prev" in
--config)
__docker_complete_configs
return
;;
--env-file)
_filedir
return
Expand Down Expand Up @@ -3151,6 +3305,8 @@ _docker_service_update_and_create() {
if [ "$subcommand" = "update" ] ; then
options_with_args="$options_with_args
--args
--config-add
--config-rm
--constraint-add
--constraint-rm
--container-label-add
Expand Down Expand Up @@ -3178,6 +3334,10 @@ _docker_service_update_and_create() {
"

case "$prev" in
--config-add|--config-rm)
__docker_complete_configs
return
;;
--group-add|--group-rm)
COMPREPLY=( $(compgen -g -- "$cur") )
return
Expand Down Expand Up @@ -3770,7 +3930,7 @@ _docker_plugin_ls() {
local key=$(__docker_map_key_of_current_option '--filter|-f')
case "$key" in
capability)
COMPREPLY=( $( compgen -W "authz ipamdriver networkdriver volumedriver" -- "${cur##*=}" ) )
COMPREPLY=( $( compgen -W "authz ipamdriver logdriver metricscollector networkdriver volumedriver" -- "${cur##*=}" ) )
return
;;
enabled)
Expand Down Expand Up @@ -3947,7 +4107,7 @@ _docker_secret_inspect() {

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) )
;;
*)
__docker_complete_secrets
Expand Down Expand Up @@ -3991,6 +4151,10 @@ _docker_secret_ls() {
}

_docker_secret_remove() {
_docker_secret_rm
}

_docker_secret_rm() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
Expand All @@ -4001,10 +4165,6 @@ _docker_secret_remove() {
esac
}

_docker_secret_rm() {
_docker_secret_remove
}



_docker_search() {
Expand Down Expand Up @@ -4375,7 +4535,7 @@ _docker_system_prune() {

case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--all -a --force -f --filter --help" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--all -a --force -f --filter --help --volumes" -- "$cur" ) )
;;
esac
}
Expand Down Expand Up @@ -4549,6 +4709,7 @@ _docker() {
shopt -s extglob

local management_commands=(
config
container
image
network
Expand Down
27 changes: 14 additions & 13 deletions components/cli/contrib/completion/zsh/_docker
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,19 @@ __docker_get_log_options() {

integer ret=1
local log_driver=${opt_args[--log-driver]:-"all"}
local -a common_options awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options
local -a common_options common_options2 awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options

common_options=("max-buffer-size" "mode")
awslogs_options=($common_options "awslogs-region" "awslogs-group" "awslogs-stream" "awslogs-create-group")
fluentd_options=($common_options "env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag")
gcplogs_options=($common_options "env" "gcp-log-cmd" "gcp-project" "labels")
gelf_options=($common_options "env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag")
journald_options=($common_options "env" "labels" "tag")
json_file_options=($common_options "env" "labels" "max-file" "max-size")
logentries_options=($common_options "logentries-token")
syslog_options=($common_options "env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag")
splunk_options=($common_options "env" "labels" "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag")
common_options2=("env" "env-regex" "labels")
awslogs_options=($common_options "awslogs-create-group" "awslogs-datetime-format" "awslogs-group" "awslogs-multiline-pattern" "awslogs-region" "awslogs-stream" "tag")
fluentd_options=($common_options $common_options2 "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "tag")
gcplogs_options=($common_options $common_options2 "gcp-log-cmd" "gcp-meta-id" "gcp-meta-name" "gcp-meta-zone" "gcp-project")
gelf_options=($common_options $common_options2 "gelf-address" "gelf-compression-level" "gelf-compression-type" "tag")
journald_options=($common_options $common_options2 "tag")
json_file_options=($common_options $common_options2 "max-file" "max-size")
logentries_options=($common_options $common_options2 "logentries-token" "tag")
syslog_options=($common_options $common_options2 "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag")
splunk_options=($common_options $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")

[[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0
[[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0
Expand Down Expand Up @@ -1960,7 +1961,6 @@ __docker_service_subcommand() {
"($help)*--mount=[Attach a filesystem mount to the service]:mount: "
"($help)*--network=[Network attachments]:network: "
"($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]"
"($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: "
"($help)--read-only[Mount the container's root filesystem as read only]"
"($help)--replicas=[Number of tasks]:replicas: "
"($help)--reserve-cpu=[Reserve CPUs]:value: "
Expand Down Expand Up @@ -2001,7 +2001,7 @@ __docker_service_subcommand() {
"($help)--mode=[Service Mode]:mode:(global replicated)" \
"($help)--name=[Service name]:name: " \
"($help)*--placement-pref=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \
"($help)*--publish=[Publish a port]:port: " \
"($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " \
"($help -): :__docker_complete_images" \
"($help -):command: _command_names -e" \
"($help -)*::arguments: _normal" && ret=0
Expand Down Expand Up @@ -2376,7 +2376,8 @@ __docker_system_subcommand() {
$opts_help \
"($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \
"($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \
"($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0
"($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" \
"($help)--volumes=[Remove all unused volumes]" && ret=0
;;
(help)
_arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0
Expand Down

0 comments on commit eb669c3

Please sign in to comment.