summaryrefslogtreecommitdiff
path: root/cmd/podman/top.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-01-02 16:29:43 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2018-01-08 19:12:17 +0000
commit7b08aa78e4ede4c54fda6cd9917bb62e18d0d634 (patch)
tree1c480d9dfb8db3268dc3fdcca827792278a3ae47 /cmd/podman/top.go
parent6baf6e461de6e560cc48d35239e7c392bec4481c (diff)
downloadpodman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.tar.gz
podman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.tar.bz2
podman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.zip
Shortcut for most recent container
It is desirable to have a shortcut for the most recently created container. We can now use "**latest" to represent the most recent container instead of its container ID or name. For example: Signed-off-by: baude <bbaude@redhat.com> Closes: #179 Approved by: baude
Diffstat (limited to 'cmd/podman/top.go')
-rw-r--r--cmd/podman/top.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/cmd/podman/top.go b/cmd/podman/top.go
index 796b31c1d..5b1dbd05c 100644
--- a/cmd/podman/top.go
+++ b/cmd/podman/top.go
@@ -16,7 +16,7 @@ var (
cli.StringFlag{
Name: "format",
Usage: "Change the output to JSON",
- },
+ }, LatestFlag,
}
topDescription = `
podman top
@@ -36,6 +36,8 @@ var (
)
func topCmd(c *cli.Context) error {
+ var container *libpod.Container
+ var err error
doJSON := false
if c.IsSet("format") {
if strings.ToUpper(c.String("format")) == "JSON" {
@@ -47,7 +49,7 @@ func topCmd(c *cli.Context) error {
args := c.Args()
var psArgs []string
psOpts := []string{"-o", "uid,pid,ppid,c,stime,tname,time,cmd"}
- if len(args) < 1 {
+ if len(args) < 1 && !c.Bool("latest") {
return errors.Errorf("you must provide the name or id of a running container")
}
if err := validateFlags(c, topFlags); err != nil {
@@ -63,7 +65,12 @@ func topCmd(c *cli.Context) error {
psOpts = args[1:]
}
- container, err := runtime.LookupContainer(args[0])
+ if c.Bool("latest") {
+ container, err = runtime.GetLatestContainer()
+ } else {
+ container, err = runtime.LookupContainer(args[0])
+ }
+
if err != nil {
return errors.Wrapf(err, "unable to lookup %s", args[0])
}