Use spf13/cobra for docker unpause
This fix is part of the effort to convert commands to spf13/cobra #23211. Thif fix coverted command `docker unpause` to use spf13/cobra Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
e94be2f639
commit
8ea7733a63
5 changed files with 52 additions and 38 deletions
|
@ -40,7 +40,6 @@ func (cli *DockerCli) Command(name string) func(...string) error {
|
||||||
"stats": cli.CmdStats,
|
"stats": cli.CmdStats,
|
||||||
"tag": cli.CmdTag,
|
"tag": cli.CmdTag,
|
||||||
"top": cli.CmdTop,
|
"top": cli.CmdTop,
|
||||||
"unpause": cli.CmdUnpause,
|
|
||||||
"update": cli.CmdUpdate,
|
"update": cli.CmdUpdate,
|
||||||
"version": cli.CmdVersion,
|
"version": cli.CmdVersion,
|
||||||
"wait": cli.CmdWait,
|
"wait": cli.CmdWait,
|
||||||
|
|
51
api/client/container/unpause.go
Normal file
51
api/client/container/unpause.go
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -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
|
|
||||||
}
|
|
|
@ -37,6 +37,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
|
||||||
container.NewExportCommand(dockerCli),
|
container.NewExportCommand(dockerCli),
|
||||||
container.NewRunCommand(dockerCli),
|
container.NewRunCommand(dockerCli),
|
||||||
container.NewStopCommand(dockerCli),
|
container.NewStopCommand(dockerCli),
|
||||||
|
container.NewUnpauseCommand(dockerCli),
|
||||||
image.NewRemoveCommand(dockerCli),
|
image.NewRemoveCommand(dockerCli),
|
||||||
image.NewSearchCommand(dockerCli),
|
image.NewSearchCommand(dockerCli),
|
||||||
volume.NewVolumeCommand(dockerCli),
|
volume.NewVolumeCommand(dockerCli),
|
||||||
|
|
|
@ -39,7 +39,6 @@ var DockerCommandUsage = []Command{
|
||||||
{"stats", "Display a live stream of container(s) resource usage statistics"},
|
{"stats", "Display a live stream of container(s) resource usage statistics"},
|
||||||
{"tag", "Tag an image into a repository"},
|
{"tag", "Tag an image into a repository"},
|
||||||
{"top", "Display the running processes of a container"},
|
{"top", "Display the running processes of a container"},
|
||||||
{"unpause", "Unpause all processes within a container"},
|
|
||||||
{"update", "Update configuration of one or more containers"},
|
{"update", "Update configuration of one or more containers"},
|
||||||
{"version", "Show the Docker version information"},
|
{"version", "Show the Docker version information"},
|
||||||
{"wait", "Block until a container stops, then print its exit code"},
|
{"wait", "Block until a container stops, then print its exit code"},
|
||||||
|
|
Loading…
Reference in a new issue