Browse code

Use ListOpt for `docker network create --label` and `docker volume create --label`

This fix is related to 27049 and 27047. For `--label` flag, if string slice is
used (like 27047), then quote can not be used in command and will result in
an error :
```
line 1, column 14: bare " in non-quoted-field
```

The issue 27047 has been fixed by 27049.

Recently I found out that both `docker network create --label` and `docker volume create --label`
still use string slice and will return the same error when quotes are used.

This fix fixes `docker network create --label` and `docker volume create --label`
by using `ListOpt` (as 27049) as well.

This fix has been tested and verified manually.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2016/10/13 08:06:34
Showing 2 changed files
... ...
@@ -20,7 +20,7 @@ type createOptions struct {
20 20
 	name       string
21 21
 	driver     string
22 22
 	driverOpts opts.MapOpts
23
-	labels     []string
23
+	labels     opts.ListOpts
24 24
 	internal   bool
25 25
 	ipv6       bool
26 26
 	attachable bool
... ...
@@ -36,6 +36,7 @@ type createOptions struct {
36 36
 func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
37 37
 	opts := createOptions{
38 38
 		driverOpts: *opts.NewMapOpts(nil, nil),
39
+		labels:     opts.NewListOpts(runconfigopts.ValidateEnv),
39 40
 		ipamAux:    *opts.NewMapOpts(nil, nil),
40 41
 		ipamOpt:    *opts.NewMapOpts(nil, nil),
41 42
 	}
... ...
@@ -53,7 +54,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
53 53
 	flags := cmd.Flags()
54 54
 	flags.StringVarP(&opts.driver, "driver", "d", "bridge", "Driver to manage the Network")
55 55
 	flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options")
56
-	flags.StringSliceVar(&opts.labels, "label", []string{}, "Set metadata on a network")
56
+	flags.Var(&opts.labels, "label", "Set metadata on a network")
57 57
 	flags.BoolVar(&opts.internal, "internal", false, "Restrict external access to the network")
58 58
 	flags.BoolVar(&opts.ipv6, "ipv6", false, "Enable IPv6 networking")
59 59
 	flags.BoolVar(&opts.attachable, "attachable", false, "Enable manual container attachment")
... ...
@@ -90,7 +91,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
90 90
 		Internal:       opts.internal,
91 91
 		EnableIPv6:     opts.ipv6,
92 92
 		Attachable:     opts.attachable,
93
-		Labels:         runconfigopts.ConvertKVStringsToMap(opts.labels),
93
+		Labels:         runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()),
94 94
 	}
95 95
 
96 96
 	resp, err := client.NetworkCreate(context.Background(), opts.name, nc)
... ...
@@ -17,12 +17,13 @@ type createOptions struct {
17 17
 	name       string
18 18
 	driver     string
19 19
 	driverOpts opts.MapOpts
20
-	labels     []string
20
+	labels     opts.ListOpts
21 21
 }
22 22
 
23 23
 func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
24 24
 	opts := createOptions{
25 25
 		driverOpts: *opts.NewMapOpts(nil, nil),
26
+		labels:     opts.NewListOpts(runconfigopts.ValidateEnv),
26 27
 	}
27 28
 
28 29
 	cmd := &cobra.Command{
... ...
@@ -46,7 +47,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
46 46
 	flags.StringVar(&opts.name, "name", "", "Specify volume name")
47 47
 	flags.Lookup("name").Hidden = true
48 48
 	flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options")
49
-	flags.StringSliceVar(&opts.labels, "label", []string{}, "Set metadata for a volume")
49
+	flags.Var(&opts.labels, "label", "Set metadata for a volume")
50 50
 
51 51
 	return cmd
52 52
 }
... ...
@@ -58,7 +59,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
58 58
 		Driver:     opts.driver,
59 59
 		DriverOpts: opts.driverOpts.GetAll(),
60 60
 		Name:       opts.name,
61
-		Labels:     runconfigopts.ConvertKVStringsToMap(opts.labels),
61
+		Labels:     runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()),
62 62
 	}
63 63
 
64 64
 	vol, err := client.VolumeCreate(context.Background(), volReq)