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

Minor cleanups in cli/command/container
This commit is contained in:
Vincent Demeester 2016-12-29 09:31:46 +01:00 committed by GitHub
commit 734f695b29
27 changed files with 109 additions and 122 deletions

View File

@ -1,18 +1,17 @@
package container package container
import ( import (
"fmt" "errors"
"io" "io"
"net/http/httputil" "net/http/httputil"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/signal"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type attachOptions struct { type attachOptions struct {
@ -54,11 +53,11 @@ func runAttach(dockerCli *command.DockerCli, opts *attachOptions) error {
} }
if !c.State.Running { 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 { 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 { if err := dockerCli.In().CheckTty(!opts.noStdin, c.Config.Tty); err != nil {

View File

@ -1,10 +1,9 @@
package container package container
import ( import (
"github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra"
) )
// NewContainerCommand returns a cobra command for `container` subcommands // NewContainerCommand returns a cobra command for `container` subcommands

View File

@ -3,13 +3,12 @@ package container
import ( import (
"fmt" "fmt"
"golang.org/x/net/context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
dockeropts "github.com/docker/docker/opts" dockeropts "github.com/docker/docker/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type commitOptions struct { type commitOptions struct {

View File

@ -1,20 +1,20 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type copyOptions struct { type copyOptions struct {
@ -53,10 +53,10 @@ func NewCopyCommand(dockerCli *command.DockerCli) *cobra.Command {
Args: cli.ExactArgs(2), Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if args[0] == "" { if args[0] == "" {
return fmt.Errorf("source can not be empty") return errors.New("source can not be empty")
} }
if args[1] == "" { if args[1] == "" {
return fmt.Errorf("destination can not be empty") return errors.New("destination can not be empty")
} }
opts.source = args[0] opts.source = args[0]
opts.destination = args[1] opts.destination = args[1]
@ -96,10 +96,10 @@ func runCopy(dockerCli *command.DockerCli, opts copyOptions) error {
return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam) return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam)
case acrossContainers: case acrossContainers:
// Copying between containers isn't supported. // 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: default:
// User didn't specify any container. // 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 content = os.Stdin
resolvedDstPath = dstInfo.Path resolvedDstPath = dstInfo.Path
if !dstInfo.IsDir { 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 { } else {
// Prepare source copy info. // Prepare source copy info.

View File

@ -5,22 +5,21 @@ import (
"io" "io"
"os" "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"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network" 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" 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/reference"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"golang.org/x/net/context"
) )
type createOptions struct { type createOptions struct {
@ -69,7 +68,7 @@ func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *createO
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID) fmt.Fprintln(dockerCli.Out(), response.ID)
return nil return nil
} }
@ -118,11 +117,12 @@ type cidFile struct {
func (cid *cidFile) Close() error { func (cid *cidFile) Close() error {
cid.file.Close() cid.file.Close()
if !cid.written { if cid.written {
return nil
}
if err := os.Remove(cid.path); err != 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 fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err)
} }
}
return nil return nil
} }

View File

@ -1,14 +1,14 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type diffOptions struct { type diffOptions struct {
@ -32,7 +32,7 @@ func NewDiffCommand(dockerCli *command.DockerCli) *cobra.Command {
func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error { func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error {
if opts.container == "" { if opts.container == "" {
return fmt.Errorf("Container name cannot be empty") return errors.New("Container name cannot be empty")
} }
ctx := context.Background() ctx := context.Background()
@ -51,7 +51,7 @@ func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error {
case archive.ChangeDelete: case archive.ChangeDelete:
kind = "D" kind = "D"
} }
fmt.Fprintf(dockerCli.Out(), "%s %s\n", kind, change.Path) fmt.Fprintln(dockerCli.Out(), kind, change.Path)
} }
return nil return nil

View File

@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"io" "io"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -15,6 +13,7 @@ import (
"github.com/docker/docker/pkg/promise" "github.com/docker/docker/pkg/promise"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type execOptions struct { type execOptions struct {
@ -88,7 +87,7 @@ func runExec(dockerCli *command.DockerCli, opts *execOptions, container string,
execID := response.ID execID := response.ID
if execID == "" { if execID == "" {
fmt.Fprintf(dockerCli.Out(), "exec ID empty") fmt.Fprintln(dockerCli.Out(), "exec ID empty")
return nil return nil
} }
@ -143,7 +142,7 @@ func runExec(dockerCli *command.DockerCli, opts *execOptions, container string,
if execConfig.Tty && dockerCli.In().IsTerminal() { if execConfig.Tty && dockerCli.In().IsTerminal() {
if err := MonitorTtySize(ctx, dockerCli, execID, true); err != nil { 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)
} }
} }

View File

@ -4,11 +4,10 @@ import (
"errors" "errors"
"io" "io"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type exportOptions struct { type exportOptions struct {

View File

@ -1,12 +1,11 @@
package container package container
import ( import (
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/command/inspect" "github.com/docker/docker/cli/command/inspect"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type inspectOptions struct { type inspectOptions struct {

View File

@ -1,14 +1,14 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type killOptions struct { type killOptions struct {
@ -46,11 +46,11 @@ func runKill(dockerCli *command.DockerCli, opts *killOptions) error {
if err := <-errChan; err != nil { if err := <-errChan; err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { } else {
fmt.Fprintf(dockerCli.Out(), "%s\n", name) fmt.Fprintln(dockerCli.Out(), name)
} }
} }
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }

View File

@ -3,8 +3,6 @@ package container
import ( import (
"io/ioutil" "io/ioutil"
"golang.org/x/net/context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
@ -12,6 +10,7 @@ import (
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/templates" "github.com/docker/docker/pkg/templates"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type psOptions struct { type psOptions struct {

View File

@ -3,13 +3,12 @@ package container
import ( import (
"io" "io"
"golang.org/x/net/context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type logsOptions struct { type logsOptions struct {

View File

@ -1,14 +1,14 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type pauseOptions struct { type pauseOptions struct {
@ -38,12 +38,12 @@ func runPause(dockerCli *command.DockerCli, opts *pauseOptions) error {
for _, container := range opts.containers { for _, container := range opts.containers {
if err := <-errChan; err != nil { if err := <-errChan; err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { continue
fmt.Fprintf(dockerCli.Out(), "%s\n", container)
} }
fmt.Fprintln(dockerCli.Out(), container)
} }
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }

View File

@ -4,12 +4,11 @@ import (
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type portOptions struct { type portOptions struct {

View File

@ -3,13 +3,12 @@ package container
import ( import (
"fmt" "fmt"
"golang.org/x/net/context"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
units "github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type pruneOptions struct { type pruneOptions struct {

View File

@ -1,14 +1,14 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type renameOptions struct { type renameOptions struct {
@ -40,11 +40,11 @@ func runRename(dockerCli *command.DockerCli, opts *renameOptions) error {
newName := strings.TrimSpace(opts.newName) newName := strings.TrimSpace(opts.newName)
if oldName == "" || 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 { 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 fmt.Errorf("Error: failed to rename container named %s", oldName)
} }
return nil return nil

View File

@ -1,15 +1,15 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"time" "time"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type restartOptions struct { type restartOptions struct {
@ -51,12 +51,12 @@ func runRestart(dockerCli *command.DockerCli, opts *restartOptions) error {
for _, name := range opts.containers { for _, name := range opts.containers {
if err := dockerCli.Client().ContainerRestart(ctx, name, timeout); err != nil { if err := dockerCli.Client().ContainerRestart(ctx, name, timeout); err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { continue
fmt.Fprintf(dockerCli.Out(), "%s\n", name)
} }
fmt.Fprintln(dockerCli.Out(), name)
} }
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }

View File

@ -1,15 +1,15 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type rmOptions struct { 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 { 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, "/") container = strings.Trim(container, "/")
if container == "" {
return errors.New("Container name cannot be empty")
}
return dockerCli.Client().ContainerRemove(ctx, container, options) return dockerCli.Client().ContainerRemove(ctx, container, options)
}) })
for _, name := range opts.containers { for _, name := range opts.containers {
if err := <-errChan; err != nil { if err := <-errChan; err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { continue
fmt.Fprintf(dockerCli.Out(), "%s\n", name)
} }
fmt.Fprintln(dockerCli.Out(), name)
} }
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }

View File

@ -1,6 +1,7 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"net/http/httputil" "net/http/httputil"
@ -9,8 +10,6 @@ import (
"strings" "strings"
"syscall" "syscall"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -22,6 +21,7 @@ import (
"github.com/docker/libnetwork/resolvconf/dns" "github.com/docker/libnetwork/resolvconf/dns"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"golang.org/x/net/context"
) )
type runOptions struct { type runOptions struct {
@ -75,8 +75,8 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
var ( var (
flAttach *opttypes.ListOpts flAttach *opttypes.ListOpts
ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d") ErrConflictAttachDetach = errors.New("Conflicting options: -a and -d")
ErrConflictRestartPolicyAndAutoRemove = fmt.Errorf("Conflicting options: --restart and --rm") ErrConflictRestartPolicyAndAutoRemove = errors.New("Conflicting options: --restart and --rm")
) )
config, hostConfig, networkingConfig, err := runconfigopts.Parse(flags, copts) config, hostConfig, networkingConfig, err := runconfigopts.Parse(flags, copts)
@ -91,7 +91,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
return ErrConflictRestartPolicyAndAutoRemove return ErrConflictRestartPolicyAndAutoRemove
} }
if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 { 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 { if len(hostConfig.DNS) > 0 {
@ -158,7 +158,7 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
waitDisplayID = make(chan struct{}) waitDisplayID = make(chan struct{})
go func() { go func() {
defer close(waitDisplayID) defer close(waitDisplayID)
fmt.Fprintf(stdout, "%s\n", createResponse.ID) fmt.Fprintln(stdout, createResponse.ID)
}() }()
} }
attach := config.AttachStdin || config.AttachStdout || config.AttachStderr attach := config.AttachStdin || config.AttachStdout || config.AttachStderr
@ -203,11 +203,10 @@ func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions
defer resp.Close() defer resp.Close()
errCh = promise.Go(func() error { errCh = promise.Go(func() error {
errHijack := holdHijackedConnection(ctx, dockerCli, config.Tty, in, out, cerr, resp) if errHijack := holdHijackedConnection(ctx, dockerCli, config.Tty, in, out, cerr, resp); errHijack != nil {
if errHijack == nil {
return errAttach
}
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 (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && dockerCli.Out().IsTerminal() {
if err := MonitorTtySize(ctx, dockerCli, createResponse.ID, false); err != nil { 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)
} }
} }

View File

@ -1,19 +1,19 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"net/http/httputil" "net/http/httputil"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/pkg/promise" "github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/signal"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type startOptions struct { type startOptions struct {
@ -59,7 +59,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
// We're going to attach to a container. // We're going to attach to a container.
// 1. Ensure we only have one container. // 1. Ensure we only have one container.
if len(opts.containers) > 1 { 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. // 2. Attach to the container.
@ -131,7 +131,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
// 5. Wait for attachment to break. // 5. Wait for attachment to break.
if c.Config.Tty && dockerCli.Out().IsTerminal() { if c.Config.Tty && dockerCli.Out().IsTerminal() {
if err := MonitorTtySize(ctx, dockerCli, c.ID, false); err != nil { 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 { if attchErr := <-cErr; attchErr != nil {
@ -143,7 +143,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
} }
} else if opts.checkpoint != "" { } else if opts.checkpoint != "" {
if len(opts.containers) > 1 { 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] container := opts.containers[0]
startOptions := types.ContainerStartOptions{ startOptions := types.ContainerStartOptions{
@ -165,15 +165,15 @@ func startContainersWithoutAttachments(ctx context.Context, dockerCli *command.D
var failedContainers []string var failedContainers []string
for _, container := range containers { for _, container := range containers {
if err := dockerCli.Client().ContainerStart(ctx, container, types.ContainerStartOptions{}); err != nil { 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) failedContainers = append(failedContainers, container)
} else { continue
fmt.Fprintf(dockerCli.Out(), "%s\n", container)
} }
fmt.Fprintln(dockerCli.Out(), container)
} }
if len(failedContainers) > 0 { 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 return nil
} }

View File

@ -1,14 +1,13 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"strings" "strings"
"sync" "sync"
"time" "time"
"golang.org/x/net/context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
@ -16,6 +15,7 @@ import (
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/command/formatter" "github.com/docker/docker/cli/command/formatter"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type statsOptions struct { type statsOptions struct {
@ -179,7 +179,7 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
} }
cStats.mu.Unlock() cStats.mu.Unlock()
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
} }

View File

@ -1,15 +1,15 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"time" "time"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type stopOptions struct { type stopOptions struct {
@ -56,12 +56,12 @@ func runStop(dockerCli *command.DockerCli, opts *stopOptions) error {
for _, container := range opts.containers { for _, container := range opts.containers {
if err := <-errChan; err != nil { if err := <-errChan; err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { continue
fmt.Fprintf(dockerCli.Out(), "%s\n", container)
} }
fmt.Fprintln(dockerCli.Out(), container)
} }
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }

View File

@ -5,11 +5,10 @@ import (
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type topOptions struct { type topOptions struct {

View File

@ -1,14 +1,14 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type unpauseOptions struct { type unpauseOptions struct {
@ -39,12 +39,12 @@ func runUnpause(dockerCli *command.DockerCli, opts *unpauseOptions) error {
for _, container := range opts.containers { for _, container := range opts.containers {
if err := <-errChan; err != nil { if err := <-errChan; err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { continue
fmt.Fprintf(dockerCli.Out(), "%s\n", container)
} }
fmt.Fprintln(dockerCli.Out(), container)
} }
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }

View File

@ -1,17 +1,17 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
containertypes "github.com/docker/docker/api/types/container" containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type updateOptions struct { type updateOptions struct {
@ -71,7 +71,7 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error {
var err error var err error
if opts.nFlag == 0 { 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 var memory int64
@ -149,15 +149,15 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error {
if err != nil { if err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { } else {
fmt.Fprintf(dockerCli.Out(), "%s\n", container) fmt.Fprintln(dockerCli.Out(), container)
} }
warns = append(warns, r.Warnings...) warns = append(warns, r.Warnings...)
} }
if len(warns) > 0 { 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 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }

View File

@ -3,8 +3,6 @@ package container
import ( import (
"strconv" "strconv"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/events"
@ -12,6 +10,7 @@ import (
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
clientapi "github.com/docker/docker/client" 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 { func waitExitOrRemoved(ctx context.Context, dockerCli *command.DockerCli, containerID string, waitRemove bool) chan int {

View File

@ -1,14 +1,14 @@
package container package container
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context"
) )
type waitOptions struct { type waitOptions struct {
@ -39,12 +39,12 @@ func runWait(dockerCli *command.DockerCli, opts *waitOptions) error {
status, err := dockerCli.Client().ContainerWait(ctx, container) status, err := dockerCli.Client().ContainerWait(ctx, container)
if err != nil { if err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { continue
}
fmt.Fprintf(dockerCli.Out(), "%d\n", status) fmt.Fprintf(dockerCli.Out(), "%d\n", status)
} }
}
if len(errs) > 0 { if len(errs) > 0 {
return fmt.Errorf("%s", strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))
} }
return nil return nil
} }