Browse code

Fix some context sharing/plumbing

With cobra switch (and maybe before), some context weren't *plumbed* the
right way, fixing that.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/06/10 00:58:10
Showing 3 changed files
... ...
@@ -38,9 +38,10 @@ func NewRestartCommand(dockerCli *client.DockerCli) *cobra.Command {
38 38
 }
39 39
 
40 40
 func runRestart(dockerCli *client.DockerCli, opts *restartOptions) error {
41
+	ctx := context.Background()
41 42
 	var errs []string
42 43
 	for _, name := range opts.containers {
43
-		if err := dockerCli.Client().ContainerRestart(context.Background(), name, time.Duration(opts.nSeconds)*time.Second); err != nil {
44
+		if err := dockerCli.Client().ContainerRestart(ctx, name, time.Duration(opts.nSeconds)*time.Second); err != nil {
44 45
 			errs = append(errs, err.Error())
45 46
 		} else {
46 47
 			fmt.Fprintf(dockerCli.Out(), "%s\n", name)
... ...
@@ -35,8 +35,10 @@ func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
35 35
 func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
36 36
 	client := dockerCli.Client()
37 37
 
38
+	ctx := context.Background()
39
+
38 40
 	getNetFunc := func(name string) (interface{}, []byte, error) {
39
-		return client.NetworkInspectWithRaw(context.Background(), name)
41
+		return client.NetworkInspectWithRaw(ctx, name)
40 42
 	}
41 43
 
42 44
 	return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getNetFunc)
... ...
@@ -35,8 +35,10 @@ func newInspectCommand(dockerCli *client.DockerCli) *cobra.Command {
35 35
 func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
36 36
 	client := dockerCli.Client()
37 37
 
38
+	ctx := context.Background()
39
+
38 40
 	getVolFunc := func(name string) (interface{}, []byte, error) {
39
-		i, err := client.VolumeInspect(context.Background(), name)
41
+		i, err := client.VolumeInspect(ctx, name)
40 42
 		return i, nil, err
41 43
 	}
42 44