summaryrefslogtreecommitdiff
path: root/cmd/kpod
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2017-11-24 09:21:09 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-27 16:46:06 +0000
commitdd88ce005f244c761e209347c63d4e65c9df9e26 (patch)
tree5c64da3091f8dfccb29a2984f040fbb5daef3fe9 /cmd/kpod
parent61e0ab4f47b63039152a5576a2f9a1741d45b654 (diff)
downloadpodman-dd88ce005f244c761e209347c63d4e65c9df9e26.tar.gz
podman-dd88ce005f244c761e209347c63d4e65c9df9e26.tar.bz2
podman-dd88ce005f244c761e209347c63d4e65c9df9e26.zip
kpod_rm: Add option for --all
Remove all containers with -a, --all. Enable kpod rm tests which were all set to skip. Add two tests for -a Signed-off-by: baude <bbaude@redhat.com> Closes: #74 Approved by: rhatdan
Diffstat (limited to 'cmd/kpod')
-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
}