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/rm.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/rm.go')
-rw-r--r-- | cmd/podman/rm.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go index dcb8fac57..8dd3475c0 100644 --- a/cmd/podman/rm.go +++ b/cmd/podman/rm.go @@ -19,6 +19,7 @@ var ( Name: "all, a", Usage: "Remove all containers", }, + LatestFlag, } rmDescription = "Remove one or more containers" rmCommand = cli.Command{ @@ -46,7 +47,11 @@ func rmCmd(c *cli.Context) error { defer runtime.Shutdown(false) args := c.Args() - if len(args) == 0 && !c.Bool("all") { + if c.Bool("latest") && c.Bool("all") { + return errors.Errorf("--all and --latest cannot be used together") + } + + if len(args) == 0 && !c.Bool("all") && !c.Bool("latest") { return errors.Errorf("specify one or more containers to remove") } @@ -57,6 +62,12 @@ func rmCmd(c *cli.Context) error { if err != nil { return errors.Wrapf(err, "unable to get container list") } + } else if c.Bool("latest") { + lastCtr, err := runtime.GetLatestContainer() + if err != nil { + return errors.Wrapf(err, "unable to get latest container") + } + delContainers = append(delContainers, lastCtr) } else { for _, i := range args { container, err := runtime.LookupContainer(i) |