summaryrefslogtreecommitdiff
path: root/cmd/podman/wait.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/wait.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/wait.go')
-rw-r--r--cmd/podman/wait.go52
1 files changed, 29 insertions, 23 deletions
diff --git a/cmd/podman/wait.go b/cmd/podman/wait.go
index 35ad7a662..fa195b7ce 100644
--- a/cmd/podman/wait.go
+++ b/cmd/podman/wait.go
@@ -5,43 +5,49 @@ import (
"os"
"time"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
+ waitCommand cliconfig.WaitValues
+
waitDescription = `
podman wait
Block until one or more containers stop and then print their exit codes
`
- waitFlags = []cli.Flag{
- cli.UintFlag{
- Name: "interval, i",
- Usage: "Milliseconds to wait before polling for completion",
- Value: 250,
+ _waitCommand = &cobra.Command{
+ Use: "wait",
+ Short: "Block on one or more containers",
+ Long: waitDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ waitCommand.InputArgs = args
+ waitCommand.GlobalFlags = MainGlobalOpts
+ return waitCmd(&waitCommand)
},
- LatestFlag,
- }
- waitCommand = cli.Command{
- Name: "wait",
- Usage: "Block on one or more containers",
- Description: waitDescription,
- Flags: sortFlags(waitFlags),
- Action: waitCmd,
- ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]",
- OnUsageError: usageErrorHandler,
+ Example: "CONTAINER-NAME [CONTAINER-NAME ...]",
}
)
-func waitCmd(c *cli.Context) error {
- args := c.Args()
- if len(args) < 1 && !c.Bool("latest") {
+func init() {
+ waitCommand.Command = _waitCommand
+ flags := waitCommand.Flags()
+ flags.UintVarP(&waitCommand.Interval, "interval", "i", 250, "Milliseconds to wait before polling for completion")
+ flags.BoolVarP(&waitCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+
+ rootCmd.AddCommand(waitCommand.Command)
+}
+
+func waitCmd(c *cliconfig.WaitValues) error {
+ args := c.InputArgs
+ if len(args) < 1 && !c.Latest {
return errors.Errorf("you must provide at least one container name or id")
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
@@ -52,7 +58,7 @@ func waitCmd(c *cli.Context) error {
}
var lastError error
- if c.Bool("latest") {
+ if c.Latest {
latestCtr, err := runtime.GetLatestContainer()
if err != nil {
return errors.Wrapf(err, "unable to wait on latest container")
@@ -65,10 +71,10 @@ func waitCmd(c *cli.Context) error {
if err != nil {
return errors.Wrapf(err, "unable to find container %s", container)
}
- if c.Uint("interval") == 0 {
+ if c.Interval == 0 {
return errors.Errorf("interval must be greater then 0")
}
- returnCode, err := ctr.WaitWithInterval(time.Duration(c.Uint("interval")) * time.Millisecond)
+ returnCode, err := ctr.WaitWithInterval(time.Duration(c.Interval) * time.Millisecond)
if err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)