From d149c93c0cf9d77687d1a0d0577ec620449247cf Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Fri, 10 Nov 2017 10:03:30 +0100 Subject: [PATCH 1/2] Fix bash completion for service env, mounts and labels `service create` and `service update` both used to have `--env`, `--label` and `--mount` options. These options now are only valid for `service create`. `service update` got corresponding `--xxx-add|rm` options instead. Signed-off-by: Harald Albers --- contrib/completion/bash/docker | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 73e655748e..48c6e2be67 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -3333,7 +3333,6 @@ _docker_service_update_and_create() { local options_with_args=" --endpoint-mode --entrypoint - --env -e --force --health-cmd --health-interval @@ -3342,12 +3341,10 @@ _docker_service_update_and_create() { --health-timeout --hostname --isolation - --label -l --limit-cpu --limit-memory --log-driver --log-opt - --mount --replicas --reserve-cpu --reserve-memory @@ -3395,11 +3392,14 @@ _docker_service_update_and_create() { --dns --dns-option --dns-search + --env -e --env-file --generic-resource --group --host + --label -l --mode + --mount --name --network --placement-pref @@ -3458,6 +3458,8 @@ _docker_service_update_and_create() { --dns-rm --dns-search-add --dns-search-rm + --env-add + --env-rm --generic-resource-add --generic-resource-rm --group-add @@ -3465,6 +3467,10 @@ _docker_service_update_and_create() { --host-add --host-rm --image + --label-add + --label-rm + --mount-add + --mount-rm --network-add --network-rm --placement-pref-add @@ -3481,6 +3487,10 @@ _docker_service_update_and_create() { __docker_complete_configs return ;; + --env-rm) + COMPREPLY=( $( compgen -e -- "$cur" ) ) + return + ;; --group-add|--group-rm) COMPREPLY=( $(compgen -g -- "$cur") ) return @@ -3527,7 +3537,7 @@ _docker_service_update_and_create() { COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) ) return ;; - --env|-e) + --env|-e|--env-add) # we do not append a "=" here because "-e VARNAME" is legal systax, too COMPREPLY=( $( compgen -e -- "$cur" ) ) __docker_nospace From f2b42bb6a8e80a7b942efbf6c4047c18ba97494c Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Fri, 10 Nov 2017 11:46:31 +0100 Subject: [PATCH 2/2] Simplify bash completion for service options Previously, the completions for `--xxx` and the corresponding `-xxx-add` and `-xxx-rm` options were defined in separate blocks. This caused a lot of duplicated code. This PR removes duplication for xxx=config|group|host|placement-pref|secret. Now the blocks for `create` and `update` only contain completions for options that either only exist for the particular command or are specific to it (completions for `--env-rm` and `--env|env-add` differ). Signed-off-by: Harald Albers --- contrib/completion/bash/docker | 81 +++++++++++----------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 48c6e2be67..39e5e38ed2 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -3408,39 +3408,14 @@ _docker_service_update_and_create() { " case "$prev" in - --config) - __docker_complete_configs - return - ;; --env-file) _filedir return ;; - --group) - COMPREPLY=( $(compgen -g -- "$cur") ) - return - ;; - --host) - case "$cur" in - *:) - __docker_complete_resolved_hostname - return - ;; - esac - ;; --mode) COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) ) return ;; - --placement-pref) - COMPREPLY=( $( compgen -W "spread" -S = -- "$cur" ) ) - __docker_nospace - return - ;; - --secret) - __docker_complete_secrets - return - ;; esac fi if [ "$subcommand" = "update" ] ; then @@ -3483,43 +3458,14 @@ _docker_service_update_and_create() { " case "$prev" in - --config-add|--config-rm) - __docker_complete_configs - return - ;; --env-rm) COMPREPLY=( $( compgen -e -- "$cur" ) ) return ;; - --group-add|--group-rm) - COMPREPLY=( $(compgen -g -- "$cur") ) - return - ;; - --host-add|--host-rm) - case "$cur" in - *:) - __docker_complete_resolved_hostname - return - ;; - esac - ;; --image) __docker_complete_image_repos_and_tags return ;; - --network-add|--network-rm) - __docker_complete_networks - return - ;; - --placement-pref-add|--placement-pref-rm) - COMPREPLY=( $( compgen -W "spread" -S = -- "$cur" ) ) - __docker_nospace - return - ;; - --secret-add|--secret-rm) - __docker_complete_secrets - return - ;; esac fi @@ -3533,6 +3479,10 @@ _docker_service_update_and_create() { esac case "$prev" in + --config|--config-add|--config-rm) + __docker_complete_configs + return + ;; --endpoint-mode) COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) ) return @@ -3543,6 +3493,18 @@ _docker_service_update_and_create() { __docker_nospace return ;; + --group|--group-add|--group-rm) + COMPREPLY=( $(compgen -g -- "$cur") ) + return + ;; + --host|--host-add|--host-rm) + case "$cur" in + *:) + __docker_complete_resolved_hostname + return + ;; + esac + ;; --isolation) __docker_complete_isolation return @@ -3555,10 +3517,15 @@ _docker_service_update_and_create() { __docker_complete_log_options return ;; - --network) + --network|--network-add|--network-rm) __docker_complete_networks return ;; + --placement-pref|--placement-pref-add|--placement-pref-rm) + COMPREPLY=( $( compgen -W "spread" -S = -- "$cur" ) ) + __docker_nospace + return + ;; --restart-condition) COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) ) return @@ -3567,6 +3534,10 @@ _docker_service_update_and_create() { COMPREPLY=( $( compgen -W "continue pause" -- "$cur" ) ) return ;; + --secret|--secret-add|--secret-rm) + __docker_complete_secrets + return + ;; --stop-signal) __docker_complete_signals return