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 case "$prev" in
--config)
__docker_complete_configs
return
;;
--env-file) --env-file)
_filedir _filedir
return return
;; ;;
--group)
COMPREPLY=( $(compgen -g -- "$cur") )
return
;;
--host)
case "$cur" in
*:)
__docker_complete_resolved_hostname
return
;;
esac
;;
--mode) --mode)
COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) ) COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) )
return return
;; ;;
--placement-pref)
COMPREPLY=( $( compgen -W "spread" -S = -- "$cur" ) )
__docker_nospace
return
;;
--secret)
__docker_complete_secrets
return
;;
esac esac
fi fi
if [ "$subcommand" = "update" ] ; then if [ "$subcommand" = "update" ] ; then
@ -3483,43 +3458,14 @@ _docker_service_update_and_create() {
" "
case "$prev" in case "$prev" in
--config-add|--config-rm)
__docker_complete_configs
return
;;
--env-rm) --env-rm)
COMPREPLY=( $( compgen -e -- "$cur" ) ) COMPREPLY=( $( compgen -e -- "$cur" ) )
return return
;; ;;
--group-add|--group-rm)
COMPREPLY=( $(compgen -g -- "$cur") )
return
;;
--host-add|--host-rm)
case "$cur" in
*:)
__docker_complete_resolved_hostname
return
;;
esac
;;
--image) --image)
__docker_complete_image_repos_and_tags __docker_complete_image_repos_and_tags
return 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 esac
fi fi
@ -3533,6 +3479,10 @@ _docker_service_update_and_create() {
esac esac
case "$prev" in case "$prev" in
--config|--config-add|--config-rm)
__docker_complete_configs
return
;;
--endpoint-mode) --endpoint-mode)
COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) ) COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) )
return return
@ -3543,6 +3493,18 @@ _docker_service_update_and_create() {
__docker_nospace __docker_nospace
return 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) --isolation)
__docker_complete_isolation __docker_complete_isolation
return return
@ -3555,10 +3517,15 @@ _docker_service_update_and_create() {
__docker_complete_log_options __docker_complete_log_options
return return
;; ;;
--network) --network|--network-add|--network-rm)
__docker_complete_networks __docker_complete_networks
return return
;; ;;
--placement-pref|--placement-pref-add|--placement-pref-rm)
COMPREPLY=( $( compgen -W "spread" -S = -- "$cur" ) )
__docker_nospace
return
;;
--restart-condition) --restart-condition)
COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) ) COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) )
return return
@ -3567,6 +3534,10 @@ _docker_service_update_and_create() {
COMPREPLY=( $( compgen -W "continue pause" -- "$cur" ) ) COMPREPLY=( $( compgen -W "continue pause" -- "$cur" ) )
return return
;; ;;
--secret|--secret-add|--secret-rm)
__docker_complete_secrets
return
;;
--stop-signal) --stop-signal)
__docker_complete_signals __docker_complete_signals
return return