From 452cb26d0d3b38ef4c0d367bee566a4f817921b1 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 14 Jun 2018 13:15:47 -0400 Subject: Implement --latest for ps Signed-off-by: Matthew Heon Closes: #944 Approved by: rhatdan --- cmd/podman/ps.go | 34 ++++++++++++++++++++++------------ 1 file 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) -- cgit v1.2.3-54-g00ecf