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 <bbaude@redhat.com>

Closes: #201
Approved by: baude
This commit is contained in:
baude
2018-01-08 14:40:29 -06:00
committed by Atomic Bot
parent da7556de4a
commit 245a338f5a
5 changed files with 34 additions and 5 deletions

View File

@ -271,12 +271,15 @@ func (r *Runtime) GetContainersByList(containers []string) ([]*Container, error)
// GetLatestContainer returns a container object of the latest created container.
func (r *Runtime) GetLatestContainer() (*Container, error) {
var lastCreatedIndex int
lastCreatedIndex := -1
var lastCreatedTime time.Time
ctrs, err := r.GetAllContainers()
if err != nil {
return nil, errors.Wrapf(err, "unable to find latest container")
}
if len(ctrs) == 0 {
return nil, ErrNoSuchCtr
}
for containerIndex, ctr := range ctrs {
createdTime := ctr.config.CreatedTime
if createdTime.After(lastCreatedTime) {