Browse code

Merge pull request #19541 from albers/completion-events

Support new events in bash completion

Vincent Demeester authored on 2016/01/22 02:40:54
Showing 1 changed files
... ...
@@ -220,6 +220,32 @@ __docker_pos_first_nonflag() {
220 220
 	echo $counter
221 221
 }
222 222
 
223
+# If we are currently completing the value of a map option (key=value)
224
+# which matches the extglob given as an argument, returns key.
225
+# This function is needed for key-specific completions.
226
+# TODO use this in all "${words[$cword-2]}$prev=" occurrences
227
+__docker_map_key_of_current_option() {
228
+	local glob="$1"
229
+
230
+	local key glob_pos
231
+	if [ "$cur" = "=" ] ; then        # key= case
232
+		key="$prev"
233
+		glob_pos=$((cword - 2))
234
+	elif [[ $cur == *=* ]] ; then     # key=value case (OSX)
235
+		key=${cur%=*}
236
+		glob_pos=$((cword - 1))
237
+	elif [ "$prev" = "=" ] ; then
238
+		key=${words[$cword - 2]}  # key=value case
239
+		glob_pos=$((cword - 3))
240
+	else
241
+		return
242
+	fi
243
+
244
+	[ "${words[$glob_pos]}" = "=" ] && ((glob_pos--))  # --option=key=value syntax
245
+
246
+	[[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
247
+}
248
+
223 249
 # Returns the value of the first option matching option_glob.
224 250
 # Valid values for option_glob are option names like '--log-level' and
225 251
 # globs like '--log-level|-l'
... ...
@@ -860,37 +886,30 @@ _docker_diff() {
860 860
 }
861 861
 
862 862
 _docker_events() {
863
-	case "$prev" in
864
-		--filter|-f)
865
-			COMPREPLY=( $( compgen -S = -W "container event image" -- "$cur" ) )
866
-			__docker_nospace
867
-			return
868
-			;;
869
-		--since|--until)
870
-			return
871
-			;;
872
-	esac
873
-
874
-	case "${words[$cword-2]}$prev=" in
875
-		*container=*)
876
-			cur="${cur#=}"
863
+	local filter=$(__docker_map_key_of_current_option '-f|--filter')
864
+	case "$filter" in
865
+		container)
866
+			cur="${cur##*=}"
877 867
 			__docker_complete_containers_all
878 868
 			return
879 869
 			;;
880
-		*event=*)
870
+		event)
881 871
 			COMPREPLY=( $( compgen -W "
882 872
 				attach
883 873
 				commit
874
+				connect
884 875
 				copy
885 876
 				create
886 877
 				delete
887 878
 				destroy
888 879
 				die
880
+				disconnect
889 881
 				exec_create
890 882
 				exec_start
891 883
 				export
892 884
 				import
893 885
 				kill
886
+				mount
894 887
 				oom
895 888
 				pause
896 889
 				pull
... ...
@@ -902,16 +921,43 @@ _docker_events() {
902 902
 				stop
903 903
 				tag
904 904
 				top
905
+				unmount
905 906
 				unpause
906 907
 				untag
907
-			" -- "${cur#=}" ) )
908
+				update
909
+			" -- "${cur##*=}" ) )
908 910
 			return
909 911
 			;;
910
-		*image=*)
911
-			cur="${cur#=}"
912
+		image)
913
+			cur="${cur##*=}"
912 914
 			__docker_complete_images
913 915
 			return
914 916
 			;;
917
+		network)
918
+			cur="${cur##*=}"
919
+			__docker_complete_networks
920
+			return
921
+			;;
922
+		type)
923
+			COMPREPLY=( $( compgen -W "container image network volume" -- "${cur##*=}" ) )
924
+			return
925
+			;;
926
+		volume)
927
+			cur="${cur##*=}"
928
+			__docker_complete_volumes
929
+			return
930
+			;;
931
+	esac
932
+
933
+	case "$prev" in
934
+		--filter|-f)
935
+			COMPREPLY=( $( compgen -S = -W "container event image label network type volume" -- "$cur" ) )
936
+			__docker_nospace
937
+			return
938
+			;;
939
+		--since|--until)
940
+			return
941
+			;;
915 942
 	esac
916 943
 
917 944
 	case "$cur" in