diff options
Diffstat (limited to 'cmd/kpod')
-rw-r--r-- | cmd/kpod/rm.go | 47 | ||||
-rw-r--r-- | cmd/kpod/wait.go | 21 |
2 files changed, 49 insertions, 19 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 } diff --git a/cmd/kpod/wait.go b/cmd/kpod/wait.go index 5e8a50e13..6e22f54e5 100644 --- a/cmd/kpod/wait.go +++ b/cmd/kpod/wait.go @@ -5,7 +5,6 @@ import ( "os" "github.com/pkg/errors" - "github.com/projectatomic/libpod/libkpod" "github.com/urfave/cli" ) @@ -31,23 +30,23 @@ func waitCmd(c *cli.Context) error { return errors.Errorf("you must provide at least one container name or id") } - config, err := getConfig(c) + runtime, err := getRuntime(c) if err != nil { - return errors.Wrapf(err, "could not get config") - } - server, err := libkpod.New(config) - if err != nil { - return errors.Wrapf(err, "could not get container server") + return errors.Wrapf(err, "error creating libpod runtime") } - defer server.Shutdown() - err = server.Update() + defer runtime.Shutdown(false) + if err != nil { - return errors.Wrapf(err, "could not update list of containers") + return errors.Wrapf(err, "could not get config") } var lastError error for _, container := range c.Args() { - returnCode, err := server.ContainerWait(container) + ctr, err := runtime.LookupContainer(container) + if err != nil { + return errors.Wrapf(err, "unable to find container %s", container) + } + returnCode, err := ctr.Wait() if err != nil { if lastError != nil { fmt.Fprintln(os.Stderr, lastError) |