summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_rm.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pod_rm.go')
-rw-r--r--cmd/podman/pod_rm.go38
1 files changed, 16 insertions, 22 deletions
diff --git a/cmd/podman/pod_rm.go b/cmd/podman/pod_rm.go
index 54cee2a50..b615f88c9 100644
--- a/cmd/podman/pod_rm.go
+++ b/cmd/podman/pod_rm.go
@@ -2,9 +2,9 @@ package main
import (
"fmt"
+ "github.com/containers/libpod/libpod/adapter"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -42,36 +42,30 @@ func init() {
}
-// saveCmd saves the image to either docker-archive or oci
+// podRmCmd deletes pods
func podRmCmd(c *cliconfig.PodRmValues) error {
if err := checkMutuallyExclusiveFlags(&c.PodmanCommand); err != nil {
return err
}
-
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
+ podRmIds, podRmErrors := runtime.RemovePods(getContext(), c)
+ for _, p := range podRmIds {
+ fmt.Println(p)
+ }
+ if len(podRmErrors) == 0 {
+ return nil
+ }
+ // Grab the last error
+ lastError := podRmErrors[len(podRmErrors)-1]
+ // Remove the last error from the error slice
+ podRmErrors = podRmErrors[:len(podRmErrors)-1]
- ctx := getContext()
- force := c.Force
-
- // getPodsFromContext returns an error when a requested pod
- // isn't found. The only fatal error scenerio is when there are no pods
- // in which case the following loop will be skipped.
- pods, lastError := getPodsFromContext(&c.PodmanCommand, runtime)
-
- for _, pod := range pods {
- err = runtime.RemovePod(ctx, pod, force, force)
- if err != nil {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "failed to delete pod %v", pod.ID())
- } else {
- fmt.Println(pod.ID())
- }
+ for _, err := range podRmErrors {
+ logrus.Errorf("%q", err)
}
return lastError
}