aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/pause.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/pause.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz
podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2
podman-25a3923b61a5ca014318e6d957f68abd03947297.zip
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the project is more well maintained. There are also some technical reasons as well which extend into our remote client work. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/pause.go')
-rw-r--r--cmd/podman/pause.go50
1 files changed, 28 insertions, 22 deletions
diff --git a/cmd/podman/pause.go b/cmd/podman/pause.go
index 2e7182871..466a3b136 100644
--- a/cmd/podman/pause.go
+++ b/cmd/podman/pause.go
@@ -3,38 +3,44 @@ package main
import (
"os"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/cmd/podman/shared"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
- pauseFlags = []cli.Flag{
- cli.BoolFlag{
- Name: "all, a",
- Usage: "Pause all running containers",
- },
- }
+ pauseCommand cliconfig.PauseValues
pauseDescription = `
podman pause
Pauses one or more running containers. The container name or ID can be used.
`
- pauseCommand = cli.Command{
- Name: "pause",
- Usage: "Pause all the processes in one or more containers",
- Description: pauseDescription,
- Flags: pauseFlags,
- Action: pauseCmd,
- ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
- OnUsageError: usageErrorHandler,
+ _pauseCommand = &cobra.Command{
+ Use: "pause",
+ Short: "Pause all the processes in one or more containers",
+ Long: pauseDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ pauseCommand.InputArgs = args
+ pauseCommand.GlobalFlags = MainGlobalOpts
+ return pauseCmd(&pauseCommand)
+ },
+ Example: "CONTAINER-NAME [CONTAINER-NAME ...]",
}
)
-func pauseCmd(c *cli.Context) error {
+func init() {
+ pauseCommand.Command = _pauseCommand
+ flags := pauseCommand.Flags()
+ flags.BoolVarP(&pauseCommand.All, "all", "a", false, "Pause all running containers")
+
+ rootCmd.AddCommand(pauseCommand.Command)
+}
+
+func pauseCmd(c *cliconfig.PauseValues) error {
var (
pauseContainers []*libpod.Container
pauseFuncs []shared.ParallelWorkerInput
@@ -43,18 +49,18 @@ func pauseCmd(c *cli.Context) error {
return errors.New("pause is not supported for rootless containers")
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- args := c.Args()
- if len(args) < 1 && !c.Bool("all") {
+ args := c.InputArgs
+ if len(args) < 1 && !c.All {
return errors.Errorf("you must provide at least one container name or id")
}
- if c.Bool("all") {
- containers, err := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running")
+ if c.All {
+ containers, err := getAllOrLatestContainers(&c.PodmanCommand, runtime, libpod.ContainerStateRunning, "running")
if err != nil {
return err
}
@@ -84,7 +90,7 @@ func pauseCmd(c *cli.Context) error {
maxWorkers := shared.Parallelize("pause")
if c.GlobalIsSet("max-workers") {
- maxWorkers = c.GlobalInt("max-workers")
+ maxWorkers = c.GlobalFlags.MaxWorks
}
logrus.Debugf("Setting maximum workers to %d", maxWorkers)