Skip to content

Commit

Permalink
Simplify bash completion for service options
Browse files Browse the repository at this point in the history
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 <github@albersweb.de>
  • Loading branch information
albers committed Dec 15, 2017
1 parent d149c93 commit f2b42bb
Showing 1 changed file with 26 additions and 55 deletions.
81 changes: 26 additions & 55 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f2b42bb

Please sign in to comment.