From 245a338f5a6519f5729749be646abbefd12701d8 Mon Sep 17 00:00:00 2001 From: baude Date: Mon, 8 Jan 2018 14:40:29 -0600 Subject: Add latest to wait It is desirable to have a --latest switch on the podman wait command so we can wait on the latest container created to end. Also, fixes a panic with latest where no containers are available. Signed-off-by: baude Closes: #201 Approved by: baude --- cmd/podman/wait.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/wait.go b/cmd/podman/wait.go index 27cfecac9..2b2a07738 100644 --- a/cmd/podman/wait.go +++ b/cmd/podman/wait.go @@ -14,11 +14,12 @@ var ( Block until one or more containers stop and then print their exit codes ` - + waitFlags = []cli.Flag{LatestFlag} waitCommand = cli.Command{ Name: "wait", Usage: "Block on one or more containers", Description: waitDescription, + Flags: waitFlags, Action: waitCmd, ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]", } @@ -26,7 +27,7 @@ var ( func waitCmd(c *cli.Context) error { args := c.Args() - if len(args) < 1 { + if len(args) < 1 && !c.Bool("latest") { return errors.Errorf("you must provide at least one container name or id") } @@ -41,7 +42,15 @@ func waitCmd(c *cli.Context) error { } var lastError error - for _, container := range c.Args() { + if c.Bool("latest") { + latestCtr, err := runtime.GetLatestContainer() + if err != nil { + return errors.Wrapf(err, "unable to wait on latest container") + } + args = append(args, latestCtr.ID()) + } + + for _, container := range args { ctr, err := runtime.LookupContainer(container) if err != nil { return errors.Wrapf(err, "unable to find container %s", container) -- cgit v1.2.3-54-g00ecf