From fceb28a0c56cf9b5a0e50d02ecf7122d594ca1d5 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Fri, 31 Jul 2015 20:02:03 +0200 Subject: [PATCH 1/2] Add completion of global options to `docker daemon` It's a bit confusing: the "global options" are valid as "global options" for all client commands (i.e. all but daemon). Example: `docker --log-level info run` For `docker daemon`, these "global options" are only valid as "command options". Example: `docker daemon --log-level info` As command completion cannot tell which command the user is going to type next, completion for the daemon command has to allow illegal syntaxes like `docker --log-level info daemon --log-level info` Signed-off-by: Harald Albers Upstream-commit: e0dad9a153fb8aad44cc36aa4bd14e297b5f120c Component: engine --- .../engine/contrib/completion/bash/docker | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/components/engine/contrib/completion/bash/docker b/components/engine/contrib/completion/bash/docker index 50b32aca21..1f397fa8cd 100644 --- a/components/engine/contrib/completion/bash/docker +++ b/components/engine/contrib/completion/bash/docker @@ -295,6 +295,10 @@ __docker_complete_log_driver_options() { return 1 } +__docker_log_levels() { + COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) +} + # a selection of the available signals that is most likely of interest in the # context of docker containers. __docker_signals() { @@ -315,16 +319,14 @@ __docker_signals() { # global options that may appear after the docker command _docker_docker() { local boolean_options=" - --debug -D + $global_boolean_options --help -h - --tls - --tlsverify --version -v " case "$prev" in --log-level|-l) - COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) + __docker_log_levels return ;; $(__docker_to_extglob "$global_options_with_args") ) @@ -453,6 +455,7 @@ _docker_create() { _docker_daemon() { local boolean_options=" + $global_boolean_options --help -h --icc=false --ip-forward=false @@ -463,6 +466,7 @@ _docker_daemon() { --userland-proxy=false " local options_with_args=" + $global_options_with_args --api-cors-header --bip --bridge -b @@ -507,6 +511,10 @@ _docker_daemon() { COMPREPLY=( $( compgen -W "aufs devicemapper btrfs overlay" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) return ;; + --log-level|-l) + __docker_log_levels + return + ;; --log-opt) __docker_log_driver_options return @@ -514,7 +522,6 @@ _docker_daemon() { $(__docker_to_extglob "$options_with_args") ) return ;; - $main_options_with_args_glob ) esac case "$cur" in @@ -1370,6 +1377,13 @@ _docker() { wait ) + # These options are valid as global options for all client commands + # and valid as command options for `docker daemon` + local global_boolean_options=" + --debug -D + --tls + --tlsverify + " local global_options_with_args=" --host -H --log-level -l From 6739612157d71843157562d103821659bb0e5da5 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Fri, 31 Jul 2015 19:25:42 +0200 Subject: [PATCH 2/2] Fix completion of commands after a global option with arg Without this fix, `docker -l info ` would not complete the commands. Signed-off-by: Harald Albers Upstream-commit: aab82c5c2230fa328bfac3c156b482634a42b73c Component: engine --- components/engine/contrib/completion/bash/docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/contrib/completion/bash/docker b/components/engine/contrib/completion/bash/docker index 1f397fa8cd..59d8a869ee 100644 --- a/components/engine/contrib/completion/bash/docker +++ b/components/engine/contrib/completion/bash/docker @@ -341,7 +341,7 @@ _docker_docker() { COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) ) ;; *) - local counter="$(__docker_pos_first_nonflag $main_options_with_args_glob)" + local counter=$( __docker_pos_first_nonflag $(__docker_to_extglob "$global_options_with_args") ) if [ $cword -eq $counter ]; then COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) fi