summaryrefslogtreecommitdiff
path: root/cmd/kpod
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2017-11-13 16:16:47 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-14 16:46:26 +0000
commit7df322123290ee600812312421b98cfb97031e9f (patch)
tree2aa3651fb88c62185706f221c385a98fd749f25b /cmd/kpod
parent55c9cfb80e066713f009547f7df7dddd2da35eb8 (diff)
downloadpodman-7df322123290ee600812312421b98cfb97031e9f.tar.gz
podman-7df322123290ee600812312421b98cfb97031e9f.tar.bz2
podman-7df322123290ee600812312421b98cfb97031e9f.zip
Remove all images
Add -a/--all to rmi so a user can remove all images quickly. Signed-off-by: baude <bbaude@redhat.com> Closes: #41 Approved by: mheon
Diffstat (limited to 'cmd/kpod')
-rw-r--r--cmd/kpod/rmi.go24
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)