Browse code

Merge pull request #29687 from thaJeztah/cleanup-cli-command-container

Minor cleanups in cli/command/container

Vincent Demeester authored on 2016/12/29 17:31:46
Showing 27 changed files
... ...
@@ -1,18 +1,17 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"fmt"
4
+	"errors"
5 5
 	"io"
6 6
 	"net/http/httputil"
7 7
 
8
-	"golang.org/x/net/context"
9
-
10 8
 	"github.com/Sirupsen/logrus"
11 9
 	"github.com/docker/docker/api/types"
12 10
 	"github.com/docker/docker/cli"
13 11
 	"github.com/docker/docker/cli/command"
14 12
 	"github.com/docker/docker/pkg/signal"
15 13
 	"github.com/spf13/cobra"
14
+	"golang.org/x/net/context"
16 15
 )
17 16
 
18 17
 type attachOptions struct {
... ...
@@ -54,11 +53,11 @@ func runAttach(dockerCli *command.DockerCli, opts *attachOptions) error {
54 54
 	}
55 55
 
56 56
 	if !c.State.Running {
57
-		return fmt.Errorf("You cannot attach to a stopped container, start it first")
57
+		return errors.New("You cannot attach to a stopped container, start it first")
58 58
 	}
59 59
 
60 60
 	if c.State.Paused {
61
-		return fmt.Errorf("You cannot attach to a paused container, unpause it first")
61
+		return errors.New("You cannot attach to a paused container, unpause it first")
62 62
 	}
63 63
 
64 64
 	if err := dockerCli.In().CheckTty(!opts.noStdin, c.Config.Tty); err != nil {
... ...
@@ -1,10 +1,9 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"github.com/spf13/cobra"
5
-
6 4
 	"github.com/docker/docker/cli"
7 5
 	"github.com/docker/docker/cli/command"
6
+	"github.com/spf13/cobra"
8 7
 )
9 8
 
10 9
 // NewContainerCommand returns a cobra command for `container` subcommands
... ...
@@ -3,13 +3,12 @@ package container
3 3
 import (
4 4
 	"fmt"
5 5
 
6
-	"golang.org/x/net/context"
7
-
8 6
 	"github.com/docker/docker/api/types"
9 7
 	"github.com/docker/docker/cli"
10 8
 	"github.com/docker/docker/cli/command"
11 9
 	dockeropts "github.com/docker/docker/opts"
12 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
13 12
 )
14 13
 
15 14
 type commitOptions struct {
... ...
@@ -1,20 +1,20 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"io"
6 7
 	"os"
7 8
 	"path/filepath"
8 9
 	"strings"
9 10
 
10
-	"golang.org/x/net/context"
11
-
12 11
 	"github.com/docker/docker/api/types"
13 12
 	"github.com/docker/docker/cli"
14 13
 	"github.com/docker/docker/cli/command"
15 14
 	"github.com/docker/docker/pkg/archive"
16 15
 	"github.com/docker/docker/pkg/system"
17 16
 	"github.com/spf13/cobra"
17
+	"golang.org/x/net/context"
18 18
 )
19 19
 
20 20
 type copyOptions struct {
... ...
@@ -53,10 +53,10 @@ func NewCopyCommand(dockerCli *command.DockerCli) *cobra.Command {
53 53
 		Args: cli.ExactArgs(2),
54 54
 		RunE: func(cmd *cobra.Command, args []string) error {
55 55
 			if args[0] == "" {
56
-				return fmt.Errorf("source can not be empty")
56
+				return errors.New("source can not be empty")
57 57
 			}
58 58
 			if args[1] == "" {
59
-				return fmt.Errorf("destination can not be empty")
59
+				return errors.New("destination can not be empty")
60 60
 			}
61 61
 			opts.source = args[0]
62 62
 			opts.destination = args[1]
... ...
@@ -96,10 +96,10 @@ func runCopy(dockerCli *command.DockerCli, opts copyOptions) error {
96 96
 		return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam)
97 97
 	case acrossContainers:
98 98
 		// Copying between containers isn't supported.
99
-		return fmt.Errorf("copying between containers is not supported")
99
+		return errors.New("copying between containers is not supported")
100 100
 	default:
101 101
 		// User didn't specify any container.
102
-		return fmt.Errorf("must specify at least one container source")
102
+		return errors.New("must specify at least one container source")
103 103
 	}
104 104
 }
105 105
 
... ...
@@ -227,7 +227,7 @@ func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath,
227 227
 		content = os.Stdin
228 228
 		resolvedDstPath = dstInfo.Path
229 229
 		if !dstInfo.IsDir {
230
-			return fmt.Errorf("destination %q must be a directory", fmt.Sprintf("%s:%s", dstContainer, dstPath))
230
+			return fmt.Errorf("destination \"%s:%s\" must be a directory", dstContainer, dstPath)
231 231
 		}
232 232
 	} else {
233 233
 		// Prepare source copy info.
... ...
@@ -5,22 +5,21 @@ import (
5 5
 	"io"
6 6
 	"os"
7 7
 
8
-	"golang.org/x/net/context"
9
-
8
+	"github.com/docker/docker/api/types"
9
+	"github.com/docker/docker/api/types/container"
10
+	networktypes "github.com/docker/docker/api/types/network"
10 11
 	"github.com/docker/docker/cli"
11 12
 	"github.com/docker/docker/cli/command"
12 13
 	"github.com/docker/docker/cli/command/image"
14
+	apiclient "github.com/docker/docker/client"
13 15
 	"github.com/docker/docker/pkg/jsonmessage"
14 16
 	// FIXME migrate to docker/distribution/reference
15
-	"github.com/docker/docker/api/types"
16
-	"github.com/docker/docker/api/types/container"
17
-	networktypes "github.com/docker/docker/api/types/network"
18
-	apiclient "github.com/docker/docker/client"
19 17
 	"github.com/docker/docker/reference"
20 18
 	"github.com/docker/docker/registry"
21 19
 	runconfigopts "github.com/docker/docker/runconfig/opts"
22 20
 	"github.com/spf13/cobra"
23 21
 	"github.com/spf13/pflag"
22
+	"golang.org/x/net/context"
24 23
 )
25 24
 
26 25
 type createOptions struct {
... ...
@@ -69,7 +68,7 @@ func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *createO
69 69
 	if err != nil {
70 70
 		return err
71 71
 	}
72
-	fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID)
72
+	fmt.Fprintln(dockerCli.Out(), response.ID)
73 73
 	return nil
74 74
 }
75 75
 
... ...
@@ -118,10 +117,11 @@ type cidFile struct {
118 118
 func (cid *cidFile) Close() error {
119 119
 	cid.file.Close()
120 120
 
121
-	if !cid.written {
122
-		if err := os.Remove(cid.path); err != nil {
123
-			return fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err)
124
-		}
121
+	if cid.written {
122
+		return nil
123
+	}
124
+	if err := os.Remove(cid.path); err != nil {
125
+		return fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err)
125 126
 	}
126 127
 
127 128
 	return nil
... ...
@@ -1,14 +1,14 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 
6
-	"golang.org/x/net/context"
7
-
8 7
 	"github.com/docker/docker/cli"
9 8
 	"github.com/docker/docker/cli/command"
10 9
 	"github.com/docker/docker/pkg/archive"
11 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
12 12
 )
13 13
 
14 14
 type diffOptions struct {
... ...
@@ -32,7 +32,7 @@ func NewDiffCommand(dockerCli *command.DockerCli) *cobra.Command {
32 32
 
33 33
 func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error {
34 34
 	if opts.container == "" {
35
-		return fmt.Errorf("Container name cannot be empty")
35
+		return errors.New("Container name cannot be empty")
36 36
 	}
37 37
 	ctx := context.Background()
38 38
 
... ...
@@ -51,7 +51,7 @@ func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error {
51 51
 		case archive.ChangeDelete:
52 52
 			kind = "D"
53 53
 		}
54
-		fmt.Fprintf(dockerCli.Out(), "%s %s\n", kind, change.Path)
54
+		fmt.Fprintln(dockerCli.Out(), kind, change.Path)
55 55
 	}
56 56
 
57 57
 	return nil
... ...
@@ -4,8 +4,6 @@ import (
4 4
 	"fmt"
5 5
 	"io"
6 6
 
7
-	"golang.org/x/net/context"
8
-
9 7
 	"github.com/Sirupsen/logrus"
10 8
 	"github.com/docker/docker/api/types"
11 9
 	"github.com/docker/docker/cli"
... ...
@@ -15,6 +13,7 @@ import (
15 15
 	"github.com/docker/docker/pkg/promise"
16 16
 	runconfigopts "github.com/docker/docker/runconfig/opts"
17 17
 	"github.com/spf13/cobra"
18
+	"golang.org/x/net/context"
18 19
 )
19 20
 
20 21
 type execOptions struct {
... ...
@@ -88,7 +87,7 @@ func runExec(dockerCli *command.DockerCli, opts *execOptions, container string,
88 88
 
89 89
 	execID := response.ID
90 90
 	if execID == "" {
91
-		fmt.Fprintf(dockerCli.Out(), "exec ID empty")
91
+		fmt.Fprintln(dockerCli.Out(), "exec ID empty")
92 92
 		return nil
93 93
 	}
94 94
 
... ...
@@ -143,7 +142,7 @@ func runExec(dockerCli *command.DockerCli, opts *execOptions, container string,
143 143
 
144 144
 	if execConfig.Tty && dockerCli.In().IsTerminal() {
145 145
 		if err := MonitorTtySize(ctx, dockerCli, execID, true); err != nil {
146
-			fmt.Fprintf(dockerCli.Err(), "Error monitoring TTY size: %s\n", err)
146
+			fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err)
147 147
 		}
148 148
 	}
149 149
 
... ...
@@ -4,11 +4,10 @@ import (
4 4
 	"errors"
5 5
 	"io"
6 6
 
7
-	"golang.org/x/net/context"
8
-
9 7
 	"github.com/docker/docker/cli"
10 8
 	"github.com/docker/docker/cli/command"
11 9
 	"github.com/spf13/cobra"
10
+	"golang.org/x/net/context"
12 11
 )
13 12
 
14 13
 type exportOptions struct {
... ...
@@ -1,12 +1,11 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"golang.org/x/net/context"
5
-
6 4
 	"github.com/docker/docker/cli"
7 5
 	"github.com/docker/docker/cli/command"
8 6
 	"github.com/docker/docker/cli/command/inspect"
9 7
 	"github.com/spf13/cobra"
8
+	"golang.org/x/net/context"
10 9
 )
11 10
 
12 11
 type inspectOptions struct {
... ...
@@ -1,14 +1,14 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
7
-	"golang.org/x/net/context"
8
-
9 8
 	"github.com/docker/docker/cli"
10 9
 	"github.com/docker/docker/cli/command"
11 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
12 12
 )
13 13
 
14 14
 type killOptions struct {
... ...
@@ -46,11 +46,11 @@ func runKill(dockerCli *command.DockerCli, opts *killOptions) error {
46 46
 		if err := <-errChan; err != nil {
47 47
 			errs = append(errs, err.Error())
48 48
 		} else {
49
-			fmt.Fprintf(dockerCli.Out(), "%s\n", name)
49
+			fmt.Fprintln(dockerCli.Out(), name)
50 50
 		}
51 51
 	}
52 52
 	if len(errs) > 0 {
53
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
53
+		return errors.New(strings.Join(errs, "\n"))
54 54
 	}
55 55
 	return nil
56 56
 }
... ...
@@ -3,8 +3,6 @@ package container
3 3
 import (
4 4
 	"io/ioutil"
5 5
 
6
-	"golang.org/x/net/context"
7
-
8 6
 	"github.com/docker/docker/api/types"
9 7
 	"github.com/docker/docker/cli"
10 8
 	"github.com/docker/docker/cli/command"
... ...
@@ -12,6 +10,7 @@ import (
12 12
 	"github.com/docker/docker/opts"
13 13
 	"github.com/docker/docker/pkg/templates"
14 14
 	"github.com/spf13/cobra"
15
+	"golang.org/x/net/context"
15 16
 )
16 17
 
17 18
 type psOptions struct {
... ...
@@ -3,13 +3,12 @@ package container
3 3
 import (
4 4
 	"io"
5 5
 
6
-	"golang.org/x/net/context"
7
-
8 6
 	"github.com/docker/docker/api/types"
9 7
 	"github.com/docker/docker/cli"
10 8
 	"github.com/docker/docker/cli/command"
11 9
 	"github.com/docker/docker/pkg/stdcopy"
12 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
13 12
 )
14 13
 
15 14
 type logsOptions struct {
... ...
@@ -1,14 +1,14 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
7
-	"golang.org/x/net/context"
8
-
9 8
 	"github.com/docker/docker/cli"
10 9
 	"github.com/docker/docker/cli/command"
11 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
12 12
 )
13 13
 
14 14
 type pauseOptions struct {
... ...
@@ -38,12 +38,12 @@ func runPause(dockerCli *command.DockerCli, opts *pauseOptions) error {
38 38
 	for _, container := range opts.containers {
39 39
 		if err := <-errChan; err != nil {
40 40
 			errs = append(errs, err.Error())
41
-		} else {
42
-			fmt.Fprintf(dockerCli.Out(), "%s\n", container)
41
+			continue
43 42
 		}
43
+		fmt.Fprintln(dockerCli.Out(), container)
44 44
 	}
45 45
 	if len(errs) > 0 {
46
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
46
+		return errors.New(strings.Join(errs, "\n"))
47 47
 	}
48 48
 	return nil
49 49
 }
... ...
@@ -4,12 +4,11 @@ import (
4 4
 	"fmt"
5 5
 	"strings"
6 6
 
7
-	"golang.org/x/net/context"
8
-
9 7
 	"github.com/docker/docker/cli"
10 8
 	"github.com/docker/docker/cli/command"
11 9
 	"github.com/docker/go-connections/nat"
12 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
13 12
 )
14 13
 
15 14
 type portOptions struct {
... ...
@@ -3,13 +3,12 @@ package container
3 3
 import (
4 4
 	"fmt"
5 5
 
6
-	"golang.org/x/net/context"
7
-
8 6
 	"github.com/docker/docker/api/types/filters"
9 7
 	"github.com/docker/docker/cli"
10 8
 	"github.com/docker/docker/cli/command"
11 9
 	units "github.com/docker/go-units"
12 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
13 12
 )
14 13
 
15 14
 type pruneOptions struct {
... ...
@@ -1,14 +1,14 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
7
-	"golang.org/x/net/context"
8
-
9 8
 	"github.com/docker/docker/cli"
10 9
 	"github.com/docker/docker/cli/command"
11 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
12 12
 )
13 13
 
14 14
 type renameOptions struct {
... ...
@@ -40,11 +40,11 @@ func runRename(dockerCli *command.DockerCli, opts *renameOptions) error {
40 40
 	newName := strings.TrimSpace(opts.newName)
41 41
 
42 42
 	if oldName == "" || newName == "" {
43
-		return fmt.Errorf("Error: Neither old nor new names may be empty")
43
+		return errors.New("Error: Neither old nor new names may be empty")
44 44
 	}
45 45
 
46 46
 	if err := dockerCli.Client().ContainerRename(ctx, oldName, newName); err != nil {
47
-		fmt.Fprintf(dockerCli.Err(), "%s\n", err)
47
+		fmt.Fprintln(dockerCli.Err(), err)
48 48
 		return fmt.Errorf("Error: failed to rename container named %s", oldName)
49 49
 	}
50 50
 	return nil
... ...
@@ -1,15 +1,15 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 	"time"
7 8
 
8
-	"golang.org/x/net/context"
9
-
10 9
 	"github.com/docker/docker/cli"
11 10
 	"github.com/docker/docker/cli/command"
12 11
 	"github.com/spf13/cobra"
12
+	"golang.org/x/net/context"
13 13
 )
14 14
 
15 15
 type restartOptions struct {
... ...
@@ -51,12 +51,12 @@ func runRestart(dockerCli *command.DockerCli, opts *restartOptions) error {
51 51
 	for _, name := range opts.containers {
52 52
 		if err := dockerCli.Client().ContainerRestart(ctx, name, timeout); err != nil {
53 53
 			errs = append(errs, err.Error())
54
-		} else {
55
-			fmt.Fprintf(dockerCli.Out(), "%s\n", name)
54
+			continue
56 55
 		}
56
+		fmt.Fprintln(dockerCli.Out(), name)
57 57
 	}
58 58
 	if len(errs) > 0 {
59
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
59
+		return errors.New(strings.Join(errs, "\n"))
60 60
 	}
61 61
 	return nil
62 62
 }
... ...
@@ -1,15 +1,15 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
7
-	"golang.org/x/net/context"
8
-
9 8
 	"github.com/docker/docker/api/types"
10 9
 	"github.com/docker/docker/cli"
11 10
 	"github.com/docker/docker/cli/command"
12 11
 	"github.com/spf13/cobra"
12
+	"golang.org/x/net/context"
13 13
 )
14 14
 
15 15
 type rmOptions struct {
... ...
@@ -52,22 +52,22 @@ func runRm(dockerCli *command.DockerCli, opts *rmOptions) error {
52 52
 	}
53 53
 
54 54
 	errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, container string) error {
55
+		container = strings.Trim(container, "/")
55 56
 		if container == "" {
56
-			return fmt.Errorf("Container name cannot be empty")
57
+			return errors.New("Container name cannot be empty")
57 58
 		}
58
-		container = strings.Trim(container, "/")
59 59
 		return dockerCli.Client().ContainerRemove(ctx, container, options)
60 60
 	})
61 61
 
62 62
 	for _, name := range opts.containers {
63 63
 		if err := <-errChan; err != nil {
64 64
 			errs = append(errs, err.Error())
65
-		} else {
66
-			fmt.Fprintf(dockerCli.Out(), "%s\n", name)
65
+			continue
67 66
 		}
67
+		fmt.Fprintln(dockerCli.Out(), name)
68 68
 	}
69 69
 	if len(errs) > 0 {
70
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
70
+		return errors.New(strings.Join(errs, "\n"))
71 71
 	}
72 72
 	return nil
73 73
 }
... ...
@@ -1,6 +1,7 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"io"
6 7
 	"net/http/httputil"
... ...
@@ -9,8 +10,6 @@ import (
9 9
 	"strings"
10 10
 	"syscall"
11 11
 
12
-	"golang.org/x/net/context"
13
-
14 12
 	"github.com/Sirupsen/logrus"
15 13
 	"github.com/docker/docker/api/types"
16 14
 	"github.com/docker/docker/cli"
... ...
@@ -22,6 +21,7 @@ import (
22 22
 	"github.com/docker/libnetwork/resolvconf/dns"
23 23
 	"github.com/spf13/cobra"
24 24
 	"github.com/spf13/pflag"
25
+	"golang.org/x/net/context"
25 26
 )
26 27
 
27 28
 type runOptions struct {
... ...
@@ -75,8 +75,8 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
75 75
 
76 76
 	var (
77 77
 		flAttach                              *opttypes.ListOpts
78
-		ErrConflictAttachDetach               = fmt.Errorf("Conflicting options: -a and -d")
79
-		ErrConflictRestartPolicyAndAutoRemove = fmt.Errorf("Conflicting options: --restart and --rm")
78
+		ErrConflictAttachDetach               = errors.New("Conflicting options: -a and -d")
79
+		ErrConflictRestartPolicyAndAutoRemove = errors.New("Conflicting options: --restart and --rm")
80 80
 	)
81 81
 
82 82
 	config, hostConfig, networkingConfig, err := runconfigopts.Parse(flags, copts)
... ...
@@ -91,7 +91,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
91 91
 		return ErrConflictRestartPolicyAndAutoRemove
92 92
 	}
93 93
 	if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 {
94
-		fmt.Fprintf(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.\n")
94
+		fmt.Fprintln(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.")
95 95
 	}
96 96
 
97 97
 	if len(hostConfig.DNS) > 0 {
... ...
@@ -158,7 +158,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
158 158
 		waitDisplayID = make(chan struct{})
159 159
 		go func() {
160 160
 			defer close(waitDisplayID)
161
-			fmt.Fprintf(stdout, "%s\n", createResponse.ID)
161
+			fmt.Fprintln(stdout, createResponse.ID)
162 162
 		}()
163 163
 	}
164 164
 	attach := config.AttachStdin || config.AttachStdout || config.AttachStderr
... ...
@@ -203,11 +203,10 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
203 203
 		defer resp.Close()
204 204
 
205 205
 		errCh = promise.Go(func() error {
206
-			errHijack := holdHijackedConnection(ctx, dockerCli, config.Tty, in, out, cerr, resp)
207
-			if errHijack == nil {
208
-				return errAttach
206
+			if errHijack := holdHijackedConnection(ctx, dockerCli, config.Tty, in, out, cerr, resp); errHijack != nil {
207
+				return errHijack
209 208
 			}
210
-			return errHijack
209
+			return errAttach
211 210
 		})
212 211
 	}
213 212
 
... ...
@@ -233,7 +232,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
233 233
 
234 234
 	if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && dockerCli.Out().IsTerminal() {
235 235
 		if err := MonitorTtySize(ctx, dockerCli, createResponse.ID, false); err != nil {
236
-			fmt.Fprintf(stderr, "Error monitoring TTY size: %s\n", err)
236
+			fmt.Fprintln(stderr, "Error monitoring TTY size:", err)
237 237
 		}
238 238
 	}
239 239
 
... ...
@@ -1,19 +1,19 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"io"
6 7
 	"net/http/httputil"
7 8
 	"strings"
8 9
 
9
-	"golang.org/x/net/context"
10
-
11 10
 	"github.com/docker/docker/api/types"
12 11
 	"github.com/docker/docker/cli"
13 12
 	"github.com/docker/docker/cli/command"
14 13
 	"github.com/docker/docker/pkg/promise"
15 14
 	"github.com/docker/docker/pkg/signal"
16 15
 	"github.com/spf13/cobra"
16
+	"golang.org/x/net/context"
17 17
 )
18 18
 
19 19
 type startOptions struct {
... ...
@@ -59,7 +59,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
59 59
 		// We're going to attach to a container.
60 60
 		// 1. Ensure we only have one container.
61 61
 		if len(opts.containers) > 1 {
62
-			return fmt.Errorf("You cannot start and attach multiple containers at once.")
62
+			return errors.New("You cannot start and attach multiple containers at once.")
63 63
 		}
64 64
 
65 65
 		// 2. Attach to the container.
... ...
@@ -131,7 +131,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
131 131
 		// 5. Wait for attachment to break.
132 132
 		if c.Config.Tty && dockerCli.Out().IsTerminal() {
133 133
 			if err := MonitorTtySize(ctx, dockerCli, c.ID, false); err != nil {
134
-				fmt.Fprintf(dockerCli.Err(), "Error monitoring TTY size: %s\n", err)
134
+				fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err)
135 135
 			}
136 136
 		}
137 137
 		if attchErr := <-cErr; attchErr != nil {
... ...
@@ -143,7 +143,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
143 143
 		}
144 144
 	} else if opts.checkpoint != "" {
145 145
 		if len(opts.containers) > 1 {
146
-			return fmt.Errorf("You cannot restore multiple containers at once.")
146
+			return errors.New("You cannot restore multiple containers at once.")
147 147
 		}
148 148
 		container := opts.containers[0]
149 149
 		startOptions := types.ContainerStartOptions{
... ...
@@ -165,15 +165,15 @@ func startContainersWithoutAttachments(ctx context.Context, dockerCli *command.D
165 165
 	var failedContainers []string
166 166
 	for _, container := range containers {
167 167
 		if err := dockerCli.Client().ContainerStart(ctx, container, types.ContainerStartOptions{}); err != nil {
168
-			fmt.Fprintf(dockerCli.Err(), "%s\n", err)
168
+			fmt.Fprintln(dockerCli.Err(), err)
169 169
 			failedContainers = append(failedContainers, container)
170
-		} else {
171
-			fmt.Fprintf(dockerCli.Out(), "%s\n", container)
170
+			continue
172 171
 		}
172
+		fmt.Fprintln(dockerCli.Out(), container)
173 173
 	}
174 174
 
175 175
 	if len(failedContainers) > 0 {
176
-		return fmt.Errorf("Error: failed to start containers: %v", strings.Join(failedContainers, ", "))
176
+		return fmt.Errorf("Error: failed to start containers: %s", strings.Join(failedContainers, ", "))
177 177
 	}
178 178
 	return nil
179 179
 }
... ...
@@ -1,14 +1,13 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"io"
6 7
 	"strings"
7 8
 	"sync"
8 9
 	"time"
9 10
 
10
-	"golang.org/x/net/context"
11
-
12 11
 	"github.com/docker/docker/api/types"
13 12
 	"github.com/docker/docker/api/types/events"
14 13
 	"github.com/docker/docker/api/types/filters"
... ...
@@ -16,6 +15,7 @@ import (
16 16
 	"github.com/docker/docker/cli/command"
17 17
 	"github.com/docker/docker/cli/command/formatter"
18 18
 	"github.com/spf13/cobra"
19
+	"golang.org/x/net/context"
19 20
 )
20 21
 
21 22
 type statsOptions struct {
... ...
@@ -179,7 +179,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
179 179
 		}
180 180
 		cStats.mu.Unlock()
181 181
 		if len(errs) > 0 {
182
-			return fmt.Errorf("%s", strings.Join(errs, "\n"))
182
+			return errors.New(strings.Join(errs, "\n"))
183 183
 		}
184 184
 	}
185 185
 
... ...
@@ -1,15 +1,15 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 	"time"
7 8
 
8
-	"golang.org/x/net/context"
9
-
10 9
 	"github.com/docker/docker/cli"
11 10
 	"github.com/docker/docker/cli/command"
12 11
 	"github.com/spf13/cobra"
12
+	"golang.org/x/net/context"
13 13
 )
14 14
 
15 15
 type stopOptions struct {
... ...
@@ -56,12 +56,12 @@ func runStop(dockerCli *command.DockerCli, opts *stopOptions) error {
56 56
 	for _, container := range opts.containers {
57 57
 		if err := <-errChan; err != nil {
58 58
 			errs = append(errs, err.Error())
59
-		} else {
60
-			fmt.Fprintf(dockerCli.Out(), "%s\n", container)
59
+			continue
61 60
 		}
61
+		fmt.Fprintln(dockerCli.Out(), container)
62 62
 	}
63 63
 	if len(errs) > 0 {
64
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
64
+		return errors.New(strings.Join(errs, "\n"))
65 65
 	}
66 66
 	return nil
67 67
 }
... ...
@@ -5,11 +5,10 @@ import (
5 5
 	"strings"
6 6
 	"text/tabwriter"
7 7
 
8
-	"golang.org/x/net/context"
9
-
10 8
 	"github.com/docker/docker/cli"
11 9
 	"github.com/docker/docker/cli/command"
12 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
13 12
 )
14 13
 
15 14
 type topOptions struct {
... ...
@@ -1,14 +1,14 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
7
-	"golang.org/x/net/context"
8
-
9 8
 	"github.com/docker/docker/cli"
10 9
 	"github.com/docker/docker/cli/command"
11 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
12 12
 )
13 13
 
14 14
 type unpauseOptions struct {
... ...
@@ -39,12 +39,12 @@ func runUnpause(dockerCli *command.DockerCli, opts *unpauseOptions) error {
39 39
 	for _, container := range opts.containers {
40 40
 		if err := <-errChan; err != nil {
41 41
 			errs = append(errs, err.Error())
42
-		} else {
43
-			fmt.Fprintf(dockerCli.Out(), "%s\n", container)
42
+			continue
44 43
 		}
44
+		fmt.Fprintln(dockerCli.Out(), container)
45 45
 	}
46 46
 	if len(errs) > 0 {
47
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
47
+		return errors.New(strings.Join(errs, "\n"))
48 48
 	}
49 49
 	return nil
50 50
 }
... ...
@@ -1,17 +1,17 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
7
-	"golang.org/x/net/context"
8
-
9 8
 	containertypes "github.com/docker/docker/api/types/container"
10 9
 	"github.com/docker/docker/cli"
11 10
 	"github.com/docker/docker/cli/command"
12 11
 	runconfigopts "github.com/docker/docker/runconfig/opts"
13 12
 	"github.com/docker/go-units"
14 13
 	"github.com/spf13/cobra"
14
+	"golang.org/x/net/context"
15 15
 )
16 16
 
17 17
 type updateOptions struct {
... ...
@@ -71,7 +71,7 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error {
71 71
 	var err error
72 72
 
73 73
 	if opts.nFlag == 0 {
74
-		return fmt.Errorf("You must provide one or more flags when using this command.")
74
+		return errors.New("You must provide one or more flags when using this command.")
75 75
 	}
76 76
 
77 77
 	var memory int64
... ...
@@ -149,15 +149,15 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error {
149 149
 		if err != nil {
150 150
 			errs = append(errs, err.Error())
151 151
 		} else {
152
-			fmt.Fprintf(dockerCli.Out(), "%s\n", container)
152
+			fmt.Fprintln(dockerCli.Out(), container)
153 153
 		}
154 154
 		warns = append(warns, r.Warnings...)
155 155
 	}
156 156
 	if len(warns) > 0 {
157
-		fmt.Fprintf(dockerCli.Out(), "%s", strings.Join(warns, "\n"))
157
+		fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n"))
158 158
 	}
159 159
 	if len(errs) > 0 {
160
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
160
+		return errors.New(strings.Join(errs, "\n"))
161 161
 	}
162 162
 	return nil
163 163
 }
... ...
@@ -3,8 +3,6 @@ package container
3 3
 import (
4 4
 	"strconv"
5 5
 
6
-	"golang.org/x/net/context"
7
-
8 6
 	"github.com/Sirupsen/logrus"
9 7
 	"github.com/docker/docker/api/types"
10 8
 	"github.com/docker/docker/api/types/events"
... ...
@@ -12,6 +10,7 @@ import (
12 12
 	"github.com/docker/docker/api/types/versions"
13 13
 	"github.com/docker/docker/cli/command"
14 14
 	clientapi "github.com/docker/docker/client"
15
+	"golang.org/x/net/context"
15 16
 )
16 17
 
17 18
 func waitExitOrRemoved(ctx context.Context, dockerCli *command.DockerCli, containerID string, waitRemove bool) chan int {
... ...
@@ -1,14 +1,14 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
7
-	"golang.org/x/net/context"
8
-
9 8
 	"github.com/docker/docker/cli"
10 9
 	"github.com/docker/docker/cli/command"
11 10
 	"github.com/spf13/cobra"
11
+	"golang.org/x/net/context"
12 12
 )
13 13
 
14 14
 type waitOptions struct {
... ...
@@ -39,12 +39,12 @@ func runWait(dockerCli *command.DockerCli, opts *waitOptions) error {
39 39
 		status, err := dockerCli.Client().ContainerWait(ctx, container)
40 40
 		if err != nil {
41 41
 			errs = append(errs, err.Error())
42
-		} else {
43
-			fmt.Fprintf(dockerCli.Out(), "%d\n", status)
42
+			continue
44 43
 		}
44
+		fmt.Fprintf(dockerCli.Out(), "%d\n", status)
45 45
 	}
46 46
 	if len(errs) > 0 {
47
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
47
+		return errors.New(strings.Join(errs, "\n"))
48 48
 	}
49 49
 	return nil
50 50
 }