Skip to content

Commit

Permalink
Merge pull request containers#7630 from Luap99/wait-n-args
Browse files Browse the repository at this point in the history
podman wait accept args > 1
  • Loading branch information
openshift-merge-robot authored Sep 15, 2020
2 parents fd7cdb2 + 685ef84 commit 5c47a33
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
9 changes: 7 additions & 2 deletions cmd/podman/containers/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var (
Short: "Block on one or more containers",
Long: waitDescription,
RunE: wait,
Args: validate.IDOrLatestArgs,
Example: `podman wait --interval 5000 ctrID
podman wait ctrID1 ctrID2`,
}
Expand All @@ -33,7 +32,6 @@ var (
Short: waitCommand.Short,
Long: waitCommand.Long,
RunE: waitCommand.RunE,
Args: validate.IDOrLatestArgs,
Example: `podman container wait --interval 5000 ctrID
podman container wait ctrID1 ctrID2`,
}
Expand Down Expand Up @@ -76,6 +74,13 @@ func wait(cmd *cobra.Command, args []string) error {
return errors.New("interval must be greater then 0")
}

if !waitOptions.Latest && len(args) == 0 {
return errors.Errorf("%q requires a name, id, or the \"--latest\" flag", cmd.CommandPath())
}
if waitOptions.Latest && len(args) > 0 {
return errors.New("--latest and containers are not allowed")
}

waitOptions.Condition, err = define.StringToContainerStatus(waitCondition)
if err != nil {
return err
Expand Down
14 changes: 10 additions & 4 deletions docs/source/markdown/podman-wait.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
podman\-wait - Wait on one or more containers to stop and print their exit codes

## SYNOPSIS
**podman wait** [*options*] *container*
**podman wait** [*options*] *container* [...]

**podman container wait** [*options*] *container*
**podman container wait** [*options*] *container* [...]

## DESCRIPTION
Waits on one or more containers to stop. The container can be referred to by its
name or ID. In the case of multiple containers, podman will wait on each consecutively.
After the container stops, the container's return code is printed.
name or ID. In the case of multiple containers, Podman will wait on each consecutively.
After all specified containers are stopped, the containers' return codes are printed
separated by newline in the same order as they were given to the command.

## OPTIONS

Expand All @@ -36,12 +37,17 @@ The latest option is not supported on the remote client.

```
$ podman wait mywebserver
0
$ podman wait --latest
0
$ podman wait 860a4b23
1
$ podman wait mywebserver myftpserver
0
125
```

## SEE ALSO
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,31 @@ var _ = Describe("Podman wait", func() {
session = podmanTest.Podman([]string{"wait", "-l"})
session.Wait(20)
})

It("podman container wait on latest container", func() {
session := podmanTest.Podman([]string{"container", "run", "-d", ALPINE, "sleep", "1"})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"container", "wait", "-l"})
session.Wait(20)
})

It("podman wait on three containers", func() {
session := podmanTest.Podman([]string{"run", "-d", ALPINE, "sleep", "1"})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
cid1 := session.OutputToString()
session = podmanTest.Podman([]string{"run", "-d", ALPINE, "sleep", "1"})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
cid2 := session.OutputToString()
session = podmanTest.Podman([]string{"run", "-d", ALPINE, "sleep", "1"})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
cid3 := session.OutputToString()
session = podmanTest.Podman([]string{"wait", cid1, cid2, cid3})
session.Wait(20)
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToStringArray()).To(Equal([]string{"0", "0", "0"}))
})
})

0 comments on commit 5c47a33

Please sign in to comment.