diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-06-14 13:15:47 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-14 19:03:52 +0000 |
commit | 452cb26d0d3b38ef4c0d367bee566a4f817921b1 (patch) | |
tree | f5cb689603fc3f8e90be28002757146cd18a2d78 /cmd/podman/ps.go | |
parent | cdb447bba2b00dfd8f473a38b75115d1cd6ee799 (diff) | |
download | podman-452cb26d0d3b38ef4c0d367bee566a4f817921b1.tar.gz podman-452cb26d0d3b38ef4c0d367bee566a4f817921b1.tar.bz2 podman-452cb26d0d3b38ef4c0d367bee566a4f817921b1.zip |
Implement --latest for ps
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #944
Approved by: rhatdan
Diffstat (limited to 'cmd/podman/ps.go')
-rw-r--r-- | cmd/podman/ps.go | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go index aa544e6d1..69911248b 100644 --- a/cmd/podman/ps.go +++ b/cmd/podman/ps.go @@ -199,20 +199,30 @@ func psCmd(c *cli.Context) error { } } - containers, err := runtime.GetContainers(filterFuncs...) - if err != nil { - return err - } - - // TODO: Latest and Last are broken right now due to lack of container - // ordering var outputContainers []*libpod.Container - if opts.Latest && len(containers) > 0 { - outputContainers = append(outputContainers, containers[0]) - } else if opts.Last > 0 && opts.Last <= len(containers) { - outputContainers = append(outputContainers, containers[:opts.Last]...) + + if !opts.Latest { + // Get all containers + containers, err := runtime.GetContainers(filterFuncs...) + if err != nil { + return err + } + + // We only want the last few containers + if opts.Last > 0 && opts.Last <= len(containers) { + return errors.Errorf("--last not yet supported") + } else { + outputContainers = containers + } } else { - outputContainers = containers + // Get just the latest container + // Ignore filters + latestCtr, err := runtime.GetLatestContainer() + if err != nil { + return err + } + + outputContainers = []*libpod.Container{latestCtr} } return generatePsOutput(outputContainers, opts) |