diff --git a/command/container/attach.go b/command/container/attach.go index 31bb109344..073914dc35 100644 --- a/command/container/attach.go +++ b/command/container/attach.go @@ -1,18 +1,17 @@ package container import ( - "fmt" + "errors" "io" "net/http/httputil" - "golang.org/x/net/context" - "github.com/Sirupsen/logrus" "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/pkg/signal" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type attachOptions struct { @@ -54,11 +53,11 @@ func runAttach(dockerCli *command.DockerCli, opts *attachOptions) error { } if !c.State.Running { - return fmt.Errorf("You cannot attach to a stopped container, start it first") + return errors.New("You cannot attach to a stopped container, start it first") } if c.State.Paused { - return fmt.Errorf("You cannot attach to a paused container, unpause it first") + return errors.New("You cannot attach to a paused container, unpause it first") } if err := dockerCli.In().CheckTty(!opts.noStdin, c.Config.Tty); err != nil { diff --git a/command/container/cmd.go b/command/container/cmd.go index 3e9b4880ac..b78411e0a3 100644 --- a/command/container/cmd.go +++ b/command/container/cmd.go @@ -1,10 +1,9 @@ package container import ( - "github.com/spf13/cobra" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" + "github.com/spf13/cobra" ) // NewContainerCommand returns a cobra command for `container` subcommands diff --git a/command/container/commit.go b/command/container/commit.go index cf8d0102a6..8f67d96d87 100644 --- a/command/container/commit.go +++ b/command/container/commit.go @@ -3,13 +3,12 @@ package container import ( "fmt" - "golang.org/x/net/context" - "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" dockeropts "github.com/docker/docker/opts" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type commitOptions struct { diff --git a/command/container/cp.go b/command/container/cp.go index 17ab2accf9..8df850b360 100644 --- a/command/container/cp.go +++ b/command/container/cp.go @@ -1,20 +1,20 @@ package container import ( + "errors" "fmt" "io" "os" "path/filepath" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/system" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type copyOptions struct { @@ -53,10 +53,10 @@ func NewCopyCommand(dockerCli *command.DockerCli) *cobra.Command { Args: cli.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { if args[0] == "" { - return fmt.Errorf("source can not be empty") + return errors.New("source can not be empty") } if args[1] == "" { - return fmt.Errorf("destination can not be empty") + return errors.New("destination can not be empty") } opts.source = args[0] opts.destination = args[1] @@ -96,10 +96,10 @@ func runCopy(dockerCli *command.DockerCli, opts copyOptions) error { return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam) case acrossContainers: // Copying between containers isn't supported. - return fmt.Errorf("copying between containers is not supported") + return errors.New("copying between containers is not supported") default: // User didn't specify any container. - return fmt.Errorf("must specify at least one container source") + return errors.New("must specify at least one container source") } } @@ -227,7 +227,7 @@ func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath, content = os.Stdin resolvedDstPath = dstInfo.Path if !dstInfo.IsDir { - return fmt.Errorf("destination %q must be a directory", fmt.Sprintf("%s:%s", dstContainer, dstPath)) + return fmt.Errorf("destination \"%s:%s\" must be a directory", dstContainer, dstPath) } } else { // Prepare source copy info. diff --git a/command/container/create.go b/command/container/create.go index 7dc644d28c..bc4fde5713 100644 --- a/command/container/create.go +++ b/command/container/create.go @@ -5,22 +5,21 @@ import ( "io" "os" - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/image" - "github.com/docker/docker/pkg/jsonmessage" - // FIXME migrate to docker/distribution/reference "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" networktypes "github.com/docker/docker/api/types/network" + "github.com/docker/docker/cli" + "github.com/docker/docker/cli/command" + "github.com/docker/docker/cli/command/image" apiclient "github.com/docker/docker/client" + "github.com/docker/docker/pkg/jsonmessage" + // FIXME migrate to docker/distribution/reference "github.com/docker/docker/reference" "github.com/docker/docker/registry" runconfigopts "github.com/docker/docker/runconfig/opts" "github.com/spf13/cobra" "github.com/spf13/pflag" + "golang.org/x/net/context" ) type createOptions struct { @@ -69,7 +68,7 @@ func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *createO if err != nil { return err } - fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID) + fmt.Fprintln(dockerCli.Out(), response.ID) return nil } @@ -118,10 +117,11 @@ type cidFile struct { func (cid *cidFile) Close() error { cid.file.Close() - if !cid.written { - if err := os.Remove(cid.path); err != nil { - return fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err) - } + if cid.written { + return nil + } + if err := os.Remove(cid.path); err != nil { + return fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err) } return nil diff --git a/command/container/diff.go b/command/container/diff.go index 168af74172..81260b05be 100644 --- a/command/container/diff.go +++ b/command/container/diff.go @@ -1,14 +1,14 @@ package container import ( + "errors" "fmt" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/pkg/archive" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type diffOptions struct { @@ -32,7 +32,7 @@ func NewDiffCommand(dockerCli *command.DockerCli) *cobra.Command { func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error { if opts.container == "" { - return fmt.Errorf("Container name cannot be empty") + return errors.New("Container name cannot be empty") } ctx := context.Background() @@ -51,7 +51,7 @@ func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error { case archive.ChangeDelete: kind = "D" } - fmt.Fprintf(dockerCli.Out(), "%s %s\n", kind, change.Path) + fmt.Fprintln(dockerCli.Out(), kind, change.Path) } return nil diff --git a/command/container/exec.go b/command/container/exec.go index f0381494e2..2253d44d54 100644 --- a/command/container/exec.go +++ b/command/container/exec.go @@ -4,8 +4,6 @@ import ( "fmt" "io" - "golang.org/x/net/context" - "github.com/Sirupsen/logrus" "github.com/docker/docker/api/types" "github.com/docker/docker/cli" @@ -15,6 +13,7 @@ import ( "github.com/docker/docker/pkg/promise" runconfigopts "github.com/docker/docker/runconfig/opts" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type execOptions struct { @@ -88,7 +87,7 @@ func runExec(dockerCli *command.DockerCli, opts *execOptions, container string, execID := response.ID if execID == "" { - fmt.Fprintf(dockerCli.Out(), "exec ID empty") + fmt.Fprintln(dockerCli.Out(), "exec ID empty") return nil } @@ -143,7 +142,7 @@ func runExec(dockerCli *command.DockerCli, opts *execOptions, container string, if execConfig.Tty && dockerCli.In().IsTerminal() { if err := MonitorTtySize(ctx, dockerCli, execID, true); err != nil { - fmt.Fprintf(dockerCli.Err(), "Error monitoring TTY size: %s\n", err) + fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err) } } diff --git a/command/container/export.go b/command/container/export.go index 8fa2e5d77e..42f90bbaaa 100644 --- a/command/container/export.go +++ b/command/container/export.go @@ -4,11 +4,10 @@ import ( "errors" "io" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type exportOptions struct { diff --git a/command/container/inspect.go b/command/container/inspect.go index 08a8d244df..d08b38dc96 100644 --- a/command/container/inspect.go +++ b/command/container/inspect.go @@ -1,12 +1,11 @@ package container import ( - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/inspect" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type inspectOptions struct { diff --git a/command/container/kill.go b/command/container/kill.go index 6da91a40e3..5c7f7ba14b 100644 --- a/command/container/kill.go +++ b/command/container/kill.go @@ -1,14 +1,14 @@ package container import ( + "errors" "fmt" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type killOptions struct { @@ -46,11 +46,11 @@ func runKill(dockerCli *command.DockerCli, opts *killOptions) error { if err := <-errChan; err != nil { errs = append(errs, err.Error()) } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", name) + fmt.Fprintln(dockerCli.Out(), name) } } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/command/container/list.go b/command/container/list.go index 5104e9b6c0..451c531a8b 100644 --- a/command/container/list.go +++ b/command/container/list.go @@ -3,8 +3,6 @@ package container import ( "io/ioutil" - "golang.org/x/net/context" - "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" @@ -12,6 +10,7 @@ import ( "github.com/docker/docker/opts" "github.com/docker/docker/pkg/templates" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type psOptions struct { diff --git a/command/container/logs.go b/command/container/logs.go index 9f1d9f90dd..2e1ce5205c 100644 --- a/command/container/logs.go +++ b/command/container/logs.go @@ -3,13 +3,12 @@ package container import ( "io" - "golang.org/x/net/context" - "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/pkg/stdcopy" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type logsOptions struct { diff --git a/command/container/pause.go b/command/container/pause.go index 6817cf60eb..7d42ca571e 100644 --- a/command/container/pause.go +++ b/command/container/pause.go @@ -1,14 +1,14 @@ package container import ( + "errors" "fmt" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type pauseOptions struct { @@ -38,12 +38,12 @@ func runPause(dockerCli *command.DockerCli, opts *pauseOptions) error { for _, container := range opts.containers { if err := <-errChan; err != nil { errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) + continue } + fmt.Fprintln(dockerCli.Out(), container) } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/command/container/port.go b/command/container/port.go index ea15290145..dd1a6b245f 100644 --- a/command/container/port.go +++ b/command/container/port.go @@ -4,12 +4,11 @@ import ( "fmt" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/go-connections/nat" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type portOptions struct { diff --git a/command/container/prune.go b/command/container/prune.go index 064f4c08e0..0aad66e6ee 100644 --- a/command/container/prune.go +++ b/command/container/prune.go @@ -3,13 +3,12 @@ package container import ( "fmt" - "golang.org/x/net/context" - "github.com/docker/docker/api/types/filters" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" units "github.com/docker/go-units" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type pruneOptions struct { diff --git a/command/container/rename.go b/command/container/rename.go index 346fb7b3b9..a24711ad3f 100644 --- a/command/container/rename.go +++ b/command/container/rename.go @@ -1,14 +1,14 @@ package container import ( + "errors" "fmt" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type renameOptions struct { @@ -40,11 +40,11 @@ func runRename(dockerCli *command.DockerCli, opts *renameOptions) error { newName := strings.TrimSpace(opts.newName) if oldName == "" || newName == "" { - return fmt.Errorf("Error: Neither old nor new names may be empty") + return errors.New("Error: Neither old nor new names may be empty") } if err := dockerCli.Client().ContainerRename(ctx, oldName, newName); err != nil { - fmt.Fprintf(dockerCli.Err(), "%s\n", err) + fmt.Fprintln(dockerCli.Err(), err) return fmt.Errorf("Error: failed to rename container named %s", oldName) } return nil diff --git a/command/container/restart.go b/command/container/restart.go index fc3ba93c84..0a3dd9218d 100644 --- a/command/container/restart.go +++ b/command/container/restart.go @@ -1,15 +1,15 @@ package container import ( + "errors" "fmt" "strings" "time" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type restartOptions struct { @@ -51,12 +51,12 @@ func runRestart(dockerCli *command.DockerCli, opts *restartOptions) error { for _, name := range opts.containers { if err := dockerCli.Client().ContainerRestart(ctx, name, timeout); err != nil { errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", name) + continue } + fmt.Fprintln(dockerCli.Out(), name) } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/command/container/rm.go b/command/container/rm.go index 60724f194b..c02533d787 100644 --- a/command/container/rm.go +++ b/command/container/rm.go @@ -1,15 +1,15 @@ package container import ( + "errors" "fmt" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type rmOptions struct { @@ -52,22 +52,22 @@ func runRm(dockerCli *command.DockerCli, opts *rmOptions) error { } errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, container string) error { - if container == "" { - return fmt.Errorf("Container name cannot be empty") - } container = strings.Trim(container, "/") + if container == "" { + return errors.New("Container name cannot be empty") + } return dockerCli.Client().ContainerRemove(ctx, container, options) }) for _, name := range opts.containers { if err := <-errChan; err != nil { errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", name) + continue } + fmt.Fprintln(dockerCli.Out(), name) } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/command/container/run.go b/command/container/run.go index 0fad93e688..2bfc49f286 100644 --- a/command/container/run.go +++ b/command/container/run.go @@ -1,6 +1,7 @@ package container import ( + "errors" "fmt" "io" "net/http/httputil" @@ -9,8 +10,6 @@ import ( "strings" "syscall" - "golang.org/x/net/context" - "github.com/Sirupsen/logrus" "github.com/docker/docker/api/types" "github.com/docker/docker/cli" @@ -22,6 +21,7 @@ import ( "github.com/docker/libnetwork/resolvconf/dns" "github.com/spf13/cobra" "github.com/spf13/pflag" + "golang.org/x/net/context" ) type runOptions struct { @@ -75,8 +75,8 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions var ( flAttach *opttypes.ListOpts - ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d") - ErrConflictRestartPolicyAndAutoRemove = fmt.Errorf("Conflicting options: --restart and --rm") + ErrConflictAttachDetach = errors.New("Conflicting options: -a and -d") + ErrConflictRestartPolicyAndAutoRemove = errors.New("Conflicting options: --restart and --rm") ) config, hostConfig, networkingConfig, err := runconfigopts.Parse(flags, copts) @@ -91,7 +91,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions return ErrConflictRestartPolicyAndAutoRemove } if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 { - fmt.Fprintf(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.\n") + fmt.Fprintln(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.") } if len(hostConfig.DNS) > 0 { @@ -158,7 +158,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions waitDisplayID = make(chan struct{}) go func() { defer close(waitDisplayID) - fmt.Fprintf(stdout, "%s\n", createResponse.ID) + fmt.Fprintln(stdout, createResponse.ID) }() } attach := config.AttachStdin || config.AttachStdout || config.AttachStderr @@ -203,11 +203,10 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions defer resp.Close() errCh = promise.Go(func() error { - errHijack := holdHijackedConnection(ctx, dockerCli, config.Tty, in, out, cerr, resp) - if errHijack == nil { - return errAttach + if errHijack := holdHijackedConnection(ctx, dockerCli, config.Tty, in, out, cerr, resp); errHijack != nil { + return errHijack } - return errHijack + return errAttach }) } @@ -233,7 +232,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && dockerCli.Out().IsTerminal() { if err := MonitorTtySize(ctx, dockerCli, createResponse.ID, false); err != nil { - fmt.Fprintf(stderr, "Error monitoring TTY size: %s\n", err) + fmt.Fprintln(stderr, "Error monitoring TTY size:", err) } } diff --git a/command/container/start.go b/command/container/start.go index 3521a41949..f5d8ca0bc4 100644 --- a/command/container/start.go +++ b/command/container/start.go @@ -1,19 +1,19 @@ package container import ( + "errors" "fmt" "io" "net/http/httputil" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/pkg/promise" "github.com/docker/docker/pkg/signal" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type startOptions struct { @@ -59,7 +59,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error { // We're going to attach to a container. // 1. Ensure we only have one container. if len(opts.containers) > 1 { - return fmt.Errorf("You cannot start and attach multiple containers at once.") + return errors.New("You cannot start and attach multiple containers at once.") } // 2. Attach to the container. @@ -131,7 +131,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error { // 5. Wait for attachment to break. if c.Config.Tty && dockerCli.Out().IsTerminal() { if err := MonitorTtySize(ctx, dockerCli, c.ID, false); err != nil { - fmt.Fprintf(dockerCli.Err(), "Error monitoring TTY size: %s\n", err) + fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err) } } if attchErr := <-cErr; attchErr != nil { @@ -143,7 +143,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error { } } else if opts.checkpoint != "" { if len(opts.containers) > 1 { - return fmt.Errorf("You cannot restore multiple containers at once.") + return errors.New("You cannot restore multiple containers at once.") } container := opts.containers[0] startOptions := types.ContainerStartOptions{ @@ -165,15 +165,15 @@ func startContainersWithoutAttachments(ctx context.Context, dockerCli *command.D var failedContainers []string for _, container := range containers { if err := dockerCli.Client().ContainerStart(ctx, container, types.ContainerStartOptions{}); err != nil { - fmt.Fprintf(dockerCli.Err(), "%s\n", err) + fmt.Fprintln(dockerCli.Err(), err) failedContainers = append(failedContainers, container) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) + continue } + fmt.Fprintln(dockerCli.Out(), container) } if len(failedContainers) > 0 { - return fmt.Errorf("Error: failed to start containers: %v", strings.Join(failedContainers, ", ")) + return fmt.Errorf("Error: failed to start containers: %s", strings.Join(failedContainers, ", ")) } return nil } diff --git a/command/container/stats.go b/command/container/stats.go index ebbd36e7e4..593db27b2a 100644 --- a/command/container/stats.go +++ b/command/container/stats.go @@ -1,14 +1,13 @@ package container import ( + "errors" "fmt" "io" "strings" "sync" "time" - "golang.org/x/net/context" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" @@ -16,6 +15,7 @@ import ( "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/formatter" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type statsOptions struct { @@ -179,7 +179,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { } cStats.mu.Unlock() if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } } diff --git a/command/container/stop.go b/command/container/stop.go index c68ede5368..48fd63a9f0 100644 --- a/command/container/stop.go +++ b/command/container/stop.go @@ -1,15 +1,15 @@ package container import ( + "errors" "fmt" "strings" "time" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type stopOptions struct { @@ -56,12 +56,12 @@ func runStop(dockerCli *command.DockerCli, opts *stopOptions) error { for _, container := range opts.containers { if err := <-errChan; err != nil { errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) + continue } + fmt.Fprintln(dockerCli.Out(), container) } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/command/container/top.go b/command/container/top.go index 160153ba7f..4a6d3ed5cf 100644 --- a/command/container/top.go +++ b/command/container/top.go @@ -5,11 +5,10 @@ import ( "strings" "text/tabwriter" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type topOptions struct { diff --git a/command/container/unpause.go b/command/container/unpause.go index c4d8d4841e..5f342da0d7 100644 --- a/command/container/unpause.go +++ b/command/container/unpause.go @@ -1,14 +1,14 @@ package container import ( + "errors" "fmt" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type unpauseOptions struct { @@ -39,12 +39,12 @@ func runUnpause(dockerCli *command.DockerCli, opts *unpauseOptions) error { for _, container := range opts.containers { if err := <-errChan; err != nil { errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) + continue } + fmt.Fprintln(dockerCli.Out(), container) } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/command/container/update.go b/command/container/update.go index 75765856c5..6a7cc820e9 100644 --- a/command/container/update.go +++ b/command/container/update.go @@ -1,17 +1,17 @@ package container import ( + "errors" "fmt" "strings" - "golang.org/x/net/context" - containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" runconfigopts "github.com/docker/docker/runconfig/opts" "github.com/docker/go-units" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type updateOptions struct { @@ -71,7 +71,7 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error { var err error if opts.nFlag == 0 { - return fmt.Errorf("You must provide one or more flags when using this command.") + return errors.New("You must provide one or more flags when using this command.") } var memory int64 @@ -149,15 +149,15 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error { if err != nil { errs = append(errs, err.Error()) } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) + fmt.Fprintln(dockerCli.Out(), container) } warns = append(warns, r.Warnings...) } if len(warns) > 0 { - fmt.Fprintf(dockerCli.Out(), "%s", strings.Join(warns, "\n")) + fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n")) } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/command/container/utils.go b/command/container/utils.go index 6bef92463c..e4664b745c 100644 --- a/command/container/utils.go +++ b/command/container/utils.go @@ -3,8 +3,6 @@ package container import ( "strconv" - "golang.org/x/net/context" - "github.com/Sirupsen/logrus" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" @@ -12,6 +10,7 @@ import ( "github.com/docker/docker/api/types/versions" "github.com/docker/docker/cli/command" clientapi "github.com/docker/docker/client" + "golang.org/x/net/context" ) func waitExitOrRemoved(ctx context.Context, dockerCli *command.DockerCli, containerID string, waitRemove bool) chan int { diff --git a/command/container/wait.go b/command/container/wait.go index 19ccf7ac25..d8dce6ef1a 100644 --- a/command/container/wait.go +++ b/command/container/wait.go @@ -1,14 +1,14 @@ package container import ( + "errors" "fmt" "strings" - "golang.org/x/net/context" - "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/spf13/cobra" + "golang.org/x/net/context" ) type waitOptions struct { @@ -39,12 +39,12 @@ func runWait(dockerCli *command.DockerCli, opts *waitOptions) error { status, err := dockerCli.Client().ContainerWait(ctx, container) if err != nil { errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%d\n", status) + continue } + fmt.Fprintf(dockerCli.Out(), "%d\n", status) } if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil }