Browse code

Add create to contrib/completion

Signed-off-by: Tibor Vass <teabee89@gmail.com>

Tibor Vass authored on 2014/08/12 02:12:09
Showing 3 changed files
... ...
@@ -217,6 +217,75 @@ _docker_cp()
217 217
 	fi
218 218
 }
219 219
 
220
+_docker_create()
221
+{
222
+	case "$prev" in
223
+		-a|--attach)
224
+			COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) )
225
+			return
226
+			;;
227
+		--cidfile|--env-file)
228
+			_filedir
229
+			return
230
+			;;
231
+		--volumes-from)
232
+			__docker_containers_all
233
+			return
234
+			;;
235
+		-v|--volume)
236
+			case "$cur" in
237
+				*:*)
238
+					# TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
239
+					;;
240
+				'')
241
+					COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
242
+					compopt -o nospace
243
+					;;
244
+				/*)
245
+					_filedir
246
+					compopt -o nospace
247
+					;;
248
+			esac
249
+			return
250
+			;;
251
+		-e|--env)
252
+			COMPREPLY=( $( compgen -e -- "$cur" ) )
253
+			compopt -o nospace
254
+			return
255
+			;;
256
+		--link)
257
+			case "$cur" in
258
+				*:*)
259
+					;;
260
+				*)
261
+					__docker_containers_running
262
+					COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) )
263
+					compopt -o nospace
264
+					;;
265
+			esac
266
+			return
267
+			;;
268
+		--entrypoint|-h|--hostname|-m|--memory|-u|--user|-w|--workdir|-c|--cpu-shares|-n|--name|-p|--publish|--expose|--dns|--lxc-conf)
269
+			return
270
+			;;
271
+		*)
272
+			;;
273
+	esac
274
+
275
+	case "$cur" in
276
+		-*)
277
+			COMPREPLY=( $( compgen -W "-n --networking --privileged -P --publish-all -i --interactive -t --tty --cidfile --entrypoint -h --hostname -m --memory -u --user -w --workdir -c --cpu-shares --name -a --attach -v --volume --link -e --env -p --publish --expose --dns --volumes-from --lxc-conf" -- "$cur" ) )
278
+			;;
279
+		*)
280
+			local counter=$(__docker_pos_first_nonflag '--cidfile|--volumes-from|-v|--volume|-e|--env|--entrypoint|-h|--hostname|-m|--memory|-u|--user|-w|--workdir|-c|--cpu-shares|-n|--name|-a|--attach|--link|-p|--publish|--expose|--dns|--lxc-conf')
281
+
282
+			if [ $cword -eq $counter ]; then
283
+				__docker_image_repos_and_tags_and_ids
284
+			fi
285
+			;;
286
+	esac
287
+}
288
+
220 289
 _docker_diff()
221 290
 {
222 291
 	local counter=$(__docker_pos_first_nonflag)
... ...
@@ -670,6 +739,7 @@ _docker()
670 670
 			build
671 671
 			commit
672 672
 			cp
673
+			create
673 674
 			diff
674 675
 			events
675 676
 			exec
... ...
@@ -16,7 +16,7 @@
16 16
 
17 17
 function __fish_docker_no_subcommand --description 'Test if docker has yet to be given the subcommand'
18 18
     for i in (commandline -opc)
19
-        if contains -- $i attach build commit cp diff events export history images import info insert inspect kill load login logs port ps pull push restart rm rmi run save search start stop tag top version wait
19
+        if contains -- $i attach build commit cp create diff events export history images import info insert inspect kill load login logs port ps pull push restart rm rmi run save search start stop tag top version wait
20 20
             return 1
21 21
         end
22 22
     end
... ...
@@ -88,6 +88,33 @@ complete -c docker -A -f -n '__fish_seen_subcommand_from commit' -a '(__fish_pri
88 88
 # cp
89 89
 complete -c docker -f -n '__fish_docker_no_subcommand' -a cp -d "Copy files/folders from a container's filesystem to the host path"
90 90
 
91
+# create
92
+complete -c docker -f -n '__fish_docker_no_subcommand' -a run -d 'Run a command in a new container'
93
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s P -l publish-all -d 'Publish all exposed ports to the host interfaces'
94
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s a -l attach -d 'Attach to stdin, stdout or stderr.'
95
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s c -l cpu-shares -d 'CPU shares (relative weight)'
96
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l cidfile -d 'Write the container ID to the file'
97
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l dns -d 'Set custom dns servers'
98
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s e -l env -d 'Set environment variables'
99
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l entrypoint -d 'Overwrite the default entrypoint of the image'
100
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l expose -d 'Expose a port from the container without publishing it to your host'
101
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s h -l hostname -d 'Container host name'
102
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s i -l interactive -d 'Keep stdin open even if not attached'
103
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l link -d 'Add link to another container (name:alias)'
104
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l lxc-conf -d 'Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"'
105
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s m -l memory -d 'Memory limit (format: <number><optional unit>, where unit = b, k, m or g)'
106
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s n -l networking -d 'Enable networking for this container'
107
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l name -d 'Assign a name to the container'
108
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s p -l publish -d "Publish a container's port to the host (format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort) (use 'docker port' to see the actual mapping)"
109
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l privileged -d 'Give extended privileges to this container'
110
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s t -l tty -d 'Allocate a pseudo-tty'
111
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s u -l user -d 'Username or UID'
112
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s v -l volume -d 'Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)'
113
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l volumes-from -d 'Mount volumes from the specified container(s)'
114
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s w -l workdir -d 'Working directory inside the container'
115
+complete -c docker -A -f -n '__fish_seen_subcommand_from run' -a '(__fish_print_docker_images)' -d "Image"
116
+
117
+
91 118
 # diff
92 119
 complete -c docker -f -n '__fish_docker_no_subcommand' -a diff -d "Inspect changes on a container's filesystem"
93 120
 complete -c docker -A -f -n '__fish_seen_subcommand_from diff' -a '(__fish_print_docker_containers all)' -d "Container"
... ...
@@ -224,6 +224,32 @@ __docker_subcommand () {
224 224
                     ;;
225 225
             esac
226 226
             ;;
227
+        (create)
228
+            _arguments \
229
+                '-P[Publish all exposed ports to the host]' \
230
+                '-a[Attach to stdin, stdout or stderr]' \
231
+                '-c=-[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)' \
232
+                '--cidfile=-[Write the container ID to the file]:CID file:_files' \
233
+                '*--dns=-[Set custom dns servers]:dns server: ' \
234
+                '*-e=-[Set environment variables]:environment variable: ' \
235
+                '--entrypoint=-[Overwrite the default entrypoint of the image]:entry point: ' \
236
+                '*--expose=-[Expose a port from the container without publishing it]: ' \
237
+                '-h=-[Container host name]:hostname:_hosts' \
238
+                '-i[Keep stdin open even if not attached]' \
239
+                '--link=-[Add link to another container]:link:->link' \
240
+                '--lxc-conf=-[Add custom lxc options]:lxc options: ' \
241
+                '-m=-[Memory limit (in bytes)]:limit: ' \
242
+                '--name=-[Container name]:name: ' \
243
+                '*-p=-[Expose a container'"'"'s port to the host]:port:_ports' \
244
+                '--privileged[Give extended privileges to this container]' \
245
+                '-t[Allocate a pseudo-tty]' \
246
+                '-u=-[Username or UID]:user:_users' \
247
+                '*-v=-[Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)]:volume: '\
248
+                '--volumes-from=-[Mount volumes from the specified container]:volume: ' \
249
+                '-w=-[Working directory inside the container]:directory:_directories' \
250
+                '(-):images:__docker_images' \
251
+                '(-):command: _command_names -e' \
252
+                '*::arguments: _normal'
227 253
         (diff|export)
228 254
             _arguments '*:containers:__docker_containers'
229 255
             ;;