diff options
Diffstat (limited to 'cmd/kpod')
-rw-r--r-- | cmd/kpod/rmi.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/cmd/kpod/rmi.go b/cmd/kpod/rmi.go index 3713db454..b69b3b514 100644 --- a/cmd/kpod/rmi.go +++ b/cmd/kpod/rmi.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/pkg/errors" + "github.com/projectatomic/libpod/libpod" "github.com/urfave/cli" ) @@ -11,6 +12,10 @@ var ( rmiDescription = "removes one or more locally stored images." rmiFlags = []cli.Flag{ cli.BoolFlag{ + Name: "all, a", + Usage: "remove all images", + }, + cli.BoolFlag{ Name: "force, f", Usage: "force removal of the image", }, @@ -29,7 +34,7 @@ func rmiCmd(c *cli.Context) error { if err := validateFlags(c, rmiFlags); err != nil { return err } - + removeAll := c.Bool("all") runtime, err := getRuntime(c) if err != nil { return errors.Wrapf(err, "could not get runtime") @@ -37,11 +42,24 @@ func rmiCmd(c *cli.Context) error { defer runtime.Shutdown(false) args := c.Args() - if len(args) == 0 { + if len(args) == 0 && !removeAll { return errors.Errorf("image name or ID must be specified") } + if len(args) > 0 && removeAll { + return errors.Errorf("when using the --all switch, you may not pass any images names or IDs") + } + imagesToDelete := args[:] + if removeAll { + localImages, err := runtime.GetImages(&libpod.ImageFilterParams{}) + if err != nil { + return errors.Wrapf(err, "unable to query local images") + } + for _, image := range localImages { + imagesToDelete = append(imagesToDelete, image.ID) + } + } - for _, arg := range args { + for _, arg := range imagesToDelete { image, err := runtime.GetImage(arg) if err != nil { return errors.Wrapf(err, "could not get image %q", arg) |