summaryrefslogtreecommitdiff
path: root/cmd/podman/volumes
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/volumes')
-rw-r--r--cmd/podman/volumes/rm.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/cmd/podman/volumes/rm.go b/cmd/podman/volumes/rm.go
index 5b23eb5e6..4c960d4d5 100644
--- a/cmd/podman/volumes/rm.go
+++ b/cmd/podman/volumes/rm.go
@@ -3,9 +3,11 @@ package volumes
import (
"context"
"fmt"
+ "strings"
"github.com/containers/podman/v2/cmd/podman/registry"
"github.com/containers/podman/v2/cmd/podman/utils"
+ "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -51,14 +53,30 @@ func rm(cmd *cobra.Command, args []string) error {
}
responses, err := registry.ContainerEngine().VolumeRm(context.Background(), args, rmOptions)
if err != nil {
+ setExitCode(err)
return err
}
for _, r := range responses {
if r.Err == nil {
fmt.Println(r.Id)
} else {
+ setExitCode(r.Err)
errs = append(errs, r.Err)
}
}
return errs.PrintErrors()
}
+
+func setExitCode(err error) {
+ cause := errors.Cause(err)
+ switch {
+ case cause == define.ErrNoSuchVolume:
+ registry.SetExitCode(1)
+ case strings.Contains(cause.Error(), define.ErrNoSuchVolume.Error()):
+ registry.SetExitCode(1)
+ case cause == define.ErrVolumeBeingUsed:
+ registry.SetExitCode(2)
+ case strings.Contains(cause.Error(), define.ErrVolumeBeingUsed.Error()):
+ registry.SetExitCode(2)
+ }
+}