From fea37b387c746471177f90f15b04d7735a88e621 Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Tue, 16 Oct 2018 12:04:45 +0000 Subject: Use the new checkAllAndLatest() function Instead of duplicating the same code in multiple commands this uses the newly added function checkAllAndLatest() instead. Signed-off-by: Adrian Reber --- cmd/podman/cleanup.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'cmd/podman/cleanup.go') diff --git a/cmd/podman/cleanup.go b/cmd/podman/cleanup.go index 3fd150783..1d8b2fbec 100644 --- a/cmd/podman/cleanup.go +++ b/cmd/podman/cleanup.go @@ -44,33 +44,25 @@ func cleanupCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - args := c.Args() - - ctx := getContext() + if err := checkAllAndLatest(c); err != nil { + return err + } var lastError error var cleanupContainers []*libpod.Container if c.Bool("all") { - if c.Bool("lastest") { - return errors.New("--all and --latest cannot be used together") - } - if len(args) != 0 { - return errors.New("--all and explicit container IDs cannot be used together") - } cleanupContainers, err = runtime.GetContainers() if err != nil { return errors.Wrapf(err, "unable to get container list") } } else if c.Bool("latest") { - if len(args) != 0 { - return errors.New("--latest and explicit container IDs cannot be used together") - } lastCtr, err := runtime.GetLatestContainer() if err != nil { return errors.Wrapf(err, "unable to get latest container") } cleanupContainers = append(cleanupContainers, lastCtr) } else { + args := c.Args() for _, i := range args { container, err := runtime.LookupContainer(i) if err != nil { @@ -81,6 +73,9 @@ func cleanupCmd(c *cli.Context) error { cleanupContainers = append(cleanupContainers, container) } } + + ctx := getContext() + for _, ctr := range cleanupContainers { if err = ctr.Cleanup(ctx); err != nil { if lastError != nil { -- cgit v1.2.3-54-g00ecf