Browse Source

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 <github@albersweb.de>
(cherry picked from commit e0dad9a153fb8aad44cc36aa4bd14e297b5f120c)
Harald Albers 10 years ago
parent
commit
5ba75ac343
1 changed files with 19 additions and 5 deletions
  1. 19 5
      contrib/completion/bash/docker

+ 19 - 5
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