diff options
author | baude <bbaude@redhat.com> | 2018-01-02 16:29:43 -0600 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-08 19:12:17 +0000 |
commit | 7b08aa78e4ede4c54fda6cd9917bb62e18d0d634 (patch) | |
tree | 1c480d9dfb8db3268dc3fdcca827792278a3ae47 /cmd/podman/stats.go | |
parent | 6baf6e461de6e560cc48d35239e7c392bec4481c (diff) | |
download | podman-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/stats.go')
-rw-r--r-- | cmd/podman/stats.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/cmd/podman/stats.go b/cmd/podman/stats.go index cf54a8bfe..d2ffd8a75 100644 --- a/cmd/podman/stats.go +++ b/cmd/podman/stats.go @@ -42,7 +42,7 @@ var ( cli.BoolFlag{ Name: "no-reset", Usage: "disable resetting the screen between intervals", - }, + }, LatestFlag, } statsDescription = "display a live stream of one or more containers' resource usage statistics" @@ -61,6 +61,15 @@ func statsCmd(c *cli.Context) error { return err } + all := c.Bool("all") + + if c.Bool("latest") && all { + return errors.Errorf("--all and --latest cannot be used together") + } + + if c.Bool("latest") && len(c.Args()) > 0 { + return errors.Errorf("no container names are allowed with --latest") + } runtime, err := getRuntime(c) if err != nil { return errors.Wrapf(err, "could not get runtime") @@ -75,7 +84,6 @@ func statsCmd(c *cli.Context) error { var format string var ctrs []*libpod.Container var containerFunc func() ([]*libpod.Container, error) - all := c.Bool("all") if c.IsSet("format") { format = c.String("format") @@ -85,6 +93,13 @@ func statsCmd(c *cli.Context) error { if len(c.Args()) > 0 { containerFunc = func() ([]*libpod.Container, error) { return runtime.GetContainersByList(c.Args()) } + } else if c.Bool("latest") { + containerFunc = func() ([]*libpod.Container, error) { + var ctrs []*libpod.Container + lastCtr, err := runtime.GetLatestContainer() + ctrs = append(ctrs, lastCtr) + return ctrs, err + } } else if all { containerFunc = runtime.GetAllContainers } else { |