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 <github@albersweb.de>
This commit is contained in:
Harald Albers 2017-11-10 11:46:31 +01:00
parent d149c93c0c
commit f2b42bb6a8
1 changed files with 26 additions and 55 deletions

View File

@ -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