From 7b08aa78e4ede4c54fda6cd9917bb62e18d0d634 Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 2 Jan 2018 16:29:43 -0600 Subject: 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 Closes: #179 Approved by: baude --- cmd/podman/rm.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'cmd/podman/rm.go') 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) -- cgit v1.2.3-54-g00ecf