aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/stop.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/stop.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/stop.go')
-rw-r--r--cmd/podman/stop.go61
1 files changed, 30 insertions, 31 deletions
diff --git a/cmd/podman/stop.go b/cmd/podman/stop.go
index 204515c70..e2c16fe20 100644
--- a/cmd/podman/stop.go
+++ b/cmd/podman/stop.go
@@ -3,27 +3,18 @@ package main
import (
"fmt"
+ "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/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
- stopFlags = []cli.Flag{
- cli.UintFlag{
- Name: "timeout, time, t",
- Usage: "Seconds to wait for stop before killing the container",
- Value: libpod.CtrRemoveTimeout,
- },
- cli.BoolFlag{
- Name: "all, a",
- Usage: "Stop all running containers",
- }, LatestFlag,
- }
+ stopCommand cliconfig.StopValues
stopDescription = `
podman stop
@@ -31,36 +22,44 @@ var (
A timeout to forcibly stop the container can also be set but defaults to 10
seconds otherwise.
`
-
- stopCommand = cli.Command{
- Name: "stop",
- Usage: "Stop one or more containers",
- Description: stopDescription,
- Flags: sortFlags(stopFlags),
- Action: stopCmd,
- ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
- OnUsageError: usageErrorHandler,
+ _stopCommand = &cobra.Command{
+ Use: "stop",
+ Short: "Stop one or more containers",
+ Long: stopDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ stopCommand.InputArgs = args
+ stopCommand.GlobalFlags = MainGlobalOpts
+ return stopCmd(&stopCommand)
+ },
+ Example: "CONTAINER-NAME [CONTAINER-NAME ...]",
}
)
-func stopCmd(c *cli.Context) error {
+func init() {
+ stopCommand.Command = _stopCommand
+ flags := stopCommand.Flags()
+ flags.BoolVarP(&stopCommand.All, "all", "a", false, "Stop all running containers")
+ flags.BoolVarP(&stopCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+ flags.UintVar(&stopCommand.Timeout, "time", libpod.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
+ flags.UintVarP(&stopCommand.Timeout, "timeout", "t", libpod.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
- if err := checkAllAndLatest(c); err != nil {
- return err
- }
+ rootCmd.AddCommand(stopCommand.Command)
+}
+
+func stopCmd(c *cliconfig.StopValues) error {
- if err := validateFlags(c, stopFlags); err != nil {
+ if err := checkAllAndLatest(&c.PodmanCommand); err != nil {
return err
}
rootless.SetSkipStorageSetup(true)
- 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)
- containers, err := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running")
+ containers, err := getAllOrLatestContainers(&c.PodmanCommand, runtime, libpod.ContainerStateRunning, "running")
if err != nil {
if len(containers) == 0 {
return err
@@ -72,8 +71,8 @@ func stopCmd(c *cli.Context) error {
for _, ctr := range containers {
con := ctr
var stopTimeout uint
- if c.IsSet("timeout") {
- stopTimeout = c.Uint("timeout")
+ if c.Flag("timeout").Changed {
+ stopTimeout = c.Timeout
} else {
stopTimeout = ctr.StopTimeout()
}
@@ -92,7 +91,7 @@ func stopCmd(c *cli.Context) error {
maxWorkers := shared.Parallelize("stop")
if c.GlobalIsSet("max-workers") {
- maxWorkers = c.GlobalInt("max-workers")
+ maxWorkers = c.GlobalFlags.MaxWorks
}
logrus.Debugf("Setting maximum workers to %d", maxWorkers)