summaryrefslogtreecommitdiff
path: root/cmd/podman/volume_rm.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/volume_rm.go')
-rw-r--r--cmd/podman/volume_rm.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/cmd/podman/volume_rm.go b/cmd/podman/volume_rm.go
index c23555b51..f301749e9 100644
--- a/cmd/podman/volume_rm.go
+++ b/cmd/podman/volume_rm.go
@@ -4,9 +4,8 @@ import (
"fmt"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
+ "github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
- "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -44,25 +43,28 @@ func init() {
func volumeRmCmd(c *cliconfig.VolumeRmValues) error {
var err error
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ if (len(c.InputArgs) > 0 && c.All) || (len(c.InputArgs) < 1 && !c.All) {
+ return errors.New("choose either one or more volumes or all")
+ }
+
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
-
- ctx := getContext()
-
- vols, lastError := getVolumesFromContext(&c.PodmanCommand, runtime)
- for _, vol := range vols {
- err = runtime.RemoveVolume(ctx, vol, c.Force, false)
- if err != nil {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "failed to remove volume %q", vol.Name())
- } else {
- fmt.Println(vol.Name())
+ deletedVolumeNames, err := runtime.RemoveVolumes(getContext(), c)
+ if err != nil {
+ if len(deletedVolumeNames) > 0 {
+ printDeleteVolumes(deletedVolumeNames)
+ return err
}
}
- return lastError
+ printDeleteVolumes(deletedVolumeNames)
+ return err
+}
+
+func printDeleteVolumes(volumes []string) {
+ for _, v := range volumes {
+ fmt.Println(v)
+ }
}