summaryrefslogtreecommitdiff
path: root/cmd/kpod/rm.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/kpod/rm.go')
-rw-r--r--cmd/kpod/rm.go47
1 files changed, 39 insertions, 8 deletions
diff --git a/cmd/kpod/rm.go b/cmd/kpod/rm.go
index 86d08f2d3..511679770 100644
--- a/cmd/kpod/rm.go
+++ b/cmd/kpod/rm.go
@@ -2,8 +2,10 @@ package main
import (
"fmt"
+ "os"
"github.com/pkg/errors"
+ "github.com/projectatomic/libpod/libpod"
"github.com/urfave/cli"
)
@@ -13,6 +15,10 @@ var (
Name: "force, f",
Usage: "Force removal of a running container. The default is false",
},
+ cli.BoolFlag{
+ Name: "all, a",
+ Usage: "Remove all containers",
+ },
}
rmDescription = "Remove one or more containers"
rmCommand = cli.Command{
@@ -39,20 +45,45 @@ func rmCmd(c *cli.Context) error {
defer runtime.Shutdown(false)
args := c.Args()
- if len(args) == 0 {
+ if len(args) == 0 && !c.Bool("all") {
return errors.Errorf("specify one or more containers to remove")
}
- for _, container := range args {
- ctr, err := runtime.LookupContainer(container)
+ var delContainers []*libpod.Container
+ var lastError error
+ if c.Bool("all") {
+ delContainers, err = runtime.GetContainers()
+ if err != nil {
+ return errors.Wrapf(err, "unable to get container list")
+ }
+ } else {
+ for _, i := range args {
+ container, err := runtime.LookupContainer(i)
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err)
+ lastError = errors.Wrapf(err, "unable to find container %s", i)
+ continue
+ }
+ delContainers = append(delContainers, container)
+ }
+ }
+ for _, container := range delContainers {
if err != nil {
- return errors.Wrapf(err, "error looking up container", container)
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = errors.Wrapf(err, "failed to find container %s", container.ID())
+ continue
}
- err = runtime.RemoveContainer(ctr, c.Bool("force"))
+ err = runtime.RemoveContainer(container, c.Bool("force"))
if err != nil {
- return errors.Wrapf(err, "error removing container %q", ctr.ID())
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = errors.Wrapf(err, "failed to delete container %v", container.ID())
+ } else {
+ fmt.Println(container.ID())
}
- fmt.Println(ctr.ID())
}
- return nil
+ return lastError
}