浏览代码

Merge pull request #23279 from yongtang/23211-spf13-cobra-unpause

Use spf13/cobra for docker unpause
Vincent Demeester 9 年之前
父节点
当前提交
b70dd0e04c
共有 5 个文件被更改,包括 52 次插入38 次删除
  1. 0 1
      api/client/commands.go
  2. 51 0
      api/client/container/unpause.go
  3. 0 36
      api/client/unpause.go
  4. 1 0
      cli/cobraadaptor/adaptor.go
  5. 0 1
      cli/usage.go

+ 0 - 1
api/client/commands.go

@@ -40,7 +40,6 @@ func (cli *DockerCli) Command(name string) func(...string) error {
 		"stats":              cli.CmdStats,
 		"tag":                cli.CmdTag,
 		"top":                cli.CmdTop,
-		"unpause":            cli.CmdUnpause,
 		"update":             cli.CmdUpdate,
 		"version":            cli.CmdVersion,
 		"wait":               cli.CmdWait,

+ 51 - 0
api/client/container/unpause.go

@@ -0,0 +1,51 @@
+package container
+
+import (
+	"fmt"
+	"strings"
+
+	"golang.org/x/net/context"
+
+	"github.com/docker/docker/api/client"
+	"github.com/docker/docker/cli"
+	"github.com/spf13/cobra"
+)
+
+type unpauseOptions struct {
+	containers []string
+}
+
+// NewUnpauseCommand creats a new cobra.Command for `docker unpause`
+func NewUnpauseCommand(dockerCli *client.DockerCli) *cobra.Command {
+	var opts unpauseOptions
+
+	cmd := &cobra.Command{
+		Use:   "unpause CONTAINER [CONTAINER...]",
+		Short: "Unpause all processes within one or more containers",
+		Args:  cli.RequiresMinArgs(1),
+		RunE: func(cmd *cobra.Command, args []string) error {
+			opts.containers = args
+			return runUnpause(dockerCli, &opts)
+		},
+	}
+	cmd.SetFlagErrorFunc(flagErrorFunc)
+
+	return cmd
+}
+
+func runUnpause(dockerCli *client.DockerCli, opts *unpauseOptions) error {
+	ctx := context.Background()
+
+	var errs []string
+	for _, container := range opts.containers {
+		if err := dockerCli.Client().ContainerUnpause(ctx, container); err != nil {
+			errs = append(errs, err.Error())
+		} else {
+			fmt.Fprintf(dockerCli.Out(), "%s\n", container)
+		}
+	}
+	if len(errs) > 0 {
+		return fmt.Errorf("%s", strings.Join(errs, "\n"))
+	}
+	return nil
+}

+ 0 - 36
api/client/unpause.go

@@ -1,36 +0,0 @@
-package client
-
-import (
-	"fmt"
-	"strings"
-
-	"golang.org/x/net/context"
-
-	Cli "github.com/docker/docker/cli"
-	flag "github.com/docker/docker/pkg/mflag"
-)
-
-// CmdUnpause unpauses all processes within a container, for one or more containers.
-//
-// Usage: docker unpause CONTAINER [CONTAINER...]
-func (cli *DockerCli) CmdUnpause(args ...string) error {
-	cmd := Cli.Subcmd("unpause", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["unpause"].Description, true)
-	cmd.Require(flag.Min, 1)
-
-	cmd.ParseFlags(args, true)
-
-	ctx := context.Background()
-
-	var errs []string
-	for _, name := range cmd.Args() {
-		if err := cli.client.ContainerUnpause(ctx, name); err != nil {
-			errs = append(errs, err.Error())
-		} else {
-			fmt.Fprintf(cli.out, "%s\n", name)
-		}
-	}
-	if len(errs) > 0 {
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
-	}
-	return nil
-}

+ 1 - 0
cli/cobraadaptor/adaptor.go

@@ -37,6 +37,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
 		container.NewExportCommand(dockerCli),
 		container.NewRunCommand(dockerCli),
 		container.NewStopCommand(dockerCli),
+		container.NewUnpauseCommand(dockerCli),
 		image.NewRemoveCommand(dockerCli),
 		image.NewSearchCommand(dockerCli),
 		volume.NewVolumeCommand(dockerCli),

+ 0 - 1
cli/usage.go

@@ -39,7 +39,6 @@ var DockerCommandUsage = []Command{
 	{"stats", "Display a live stream of container(s) resource usage statistics"},
 	{"tag", "Tag an image into a repository"},
 	{"top", "Display the running processes of a container"},
-	{"unpause", "Unpause all processes within a container"},
 	{"update", "Update configuration of one or more containers"},
 	{"version", "Show the Docker version information"},
 	{"wait", "Block until a container stops, then print its exit code"},