浏览代码

Merge pull request #17107 from albers/completion-build

Add missing options to bash completion for `docker build`
Tibor Vass 9 年之前
父节点
当前提交
b1bab9e1e7
共有 1 个文件被更改,包括 39 次插入7 次删除
  1. 39 7
      contrib/completion/bash/docker

+ 39 - 7
contrib/completion/bash/docker

@@ -461,8 +461,37 @@ _docker_attach() {
 }
 
 _docker_build() {
+	local options_with_args="
+		--build-arg
+		--cgroup-parent
+		--cpuset-cpus
+		--cpuset-mems
+		--cpu-shares -c
+		--cpu-period
+		--cpu-quota
+		--file -f
+		--memory -m
+		--memory-swap
+		--tag -t
+		--ulimit
+	"
+
+	local boolean_options="
+		--disable-content-trust=false
+		--force-rm
+		--help
+		--no-cache
+		--pull
+		--quiet -q
+		--rm
+	"
+
+	local all_options="$options_with_args $boolean_options"
+
 	case "$prev" in
-		--cgroup-parent|--cpuset-cpus|--cpuset-mems|--cpu-shares|-c|--cpu-period|--cpu-quota|--memory|-m|--memory-swap)
+		--build-arg)
+			COMPREPLY=( $( compgen -e -- "$cur" ) )
+			__docker_nospace
 			return
 			;;
 		--file|-f)
@@ -473,14 +502,17 @@ _docker_build() {
 			__docker_image_repos_and_tags
 			return
 			;;
+		$(__docker_to_extglob "$options_with_args") )
+			return
+			;;
 	esac
 
 	case "$cur" in
 		-*)
-			COMPREPLY=( $( compgen -W "--cgroup-parent --cpuset-cpus --cpuset-mems --cpu-shares -c --cpu-period --cpu-quota --file -f --force-rm --help --memory -m --memory-swap --no-cache --pull --quiet -q --rm --tag -t --ulimit" -- "$cur" ) )
+			COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
 			;;
 		*)
-			local counter="$(__docker_pos_first_nonflag '--cgroup-parent|--cpuset-cpus|--cpuset-mems|--cpu-shares|-c|--cpu-period|--cpu-quota|--file|-f|--memory|-m|--memory-swap|--tag|-t')"
+			local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) )
 			if [ $cword -eq $counter ]; then
 				_filedir -d
 			fi
@@ -1311,7 +1343,7 @@ _docker_run() {
 		--workdir -w
 	"
 
-	local all_options="$options_with_args
+	local boolean_options="
 		--disable-content-trust=false
 		--help
 		--interactive -i
@@ -1322,14 +1354,14 @@ _docker_run() {
 		--tty -t
 	"
 
+	local all_options="$options_with_args $boolean_options"
+
 	[ "$command" = "run" ] && all_options="$all_options
 		--detach -d
 		--rm
 		--sig-proxy=false
 	"
 
-	local options_with_args_glob=$(__docker_to_extglob "$options_with_args")
-
 	case "$prev" in
 		--add-host)
 			case "$cur" in
@@ -1454,7 +1486,7 @@ _docker_run() {
 			__docker_containers_all
 			return
 			;;
-		$options_with_args_glob )
+		$(__docker_to_extglob "$options_with_args") )
 			return
 			;;
 	esac