diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/errors.go | 13 | ||||
-rw-r--r-- | cmd/podman/errors_remote.go | 20 | ||||
-rw-r--r-- | cmd/podman/rm.go | 13 | ||||
-rw-r--r-- | cmd/podman/rmi.go | 1 |
4 files changed, 39 insertions, 8 deletions
diff --git a/cmd/podman/errors.go b/cmd/podman/errors.go index 9731037f4..ae9e73e62 100644 --- a/cmd/podman/errors.go +++ b/cmd/podman/errors.go @@ -8,6 +8,8 @@ import ( "os/exec" "syscall" + "github.com/containers/libpod/libpod/define" + "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -24,3 +26,14 @@ func outputError(err error) { fmt.Fprintln(os.Stderr, "Error:", err.Error()) } } + +func setExitCode(err error) int { + cause := errors.Cause(err) + switch cause { + case define.ErrNoSuchCtr: + return 1 + case define.ErrCtrStateInvalid: + return 2 + } + return exitCode +} diff --git a/cmd/podman/errors_remote.go b/cmd/podman/errors_remote.go index 1e276be10..19df2d2d8 100644 --- a/cmd/podman/errors_remote.go +++ b/cmd/podman/errors_remote.go @@ -9,6 +9,7 @@ import ( "syscall" "github.com/containers/libpod/cmd/podman/varlink" + "github.com/containers/libpod/libpod/define" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -43,3 +44,22 @@ func outputError(err error) { fmt.Fprintln(os.Stderr, "Error:", ne.Error()) } } + +func setExitCode(err error) int { + cause := errors.Cause(err) + switch e := cause.(type) { + // For some reason golang wont let me list them with commas so listing them all. + case *iopodman.ContainerNotFound: + return 1 + case *iopodman.InvalidState: + return 2 + default: + switch e { + case define.ErrNoSuchCtr: + return 1 + case define.ErrCtrStateInvalid: + return 2 + } + } + return exitCode +} diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go index 958ca1c60..9e3ce4d0b 100644 --- a/cmd/podman/rm.go +++ b/cmd/podman/rm.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/containers/libpod/cmd/podman/cliconfig" - "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/adapter" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -65,18 +64,16 @@ func rmCmd(c *cliconfig.RmValues) error { ok, failures, err := runtime.RemoveContainers(getContext(), c) if err != nil { - if errors.Cause(err) == define.ErrNoSuchCtr { - if len(c.InputArgs) > 1 { - exitCode = 125 - } else { - exitCode = 1 - } + if len(c.InputArgs) < 2 { + exitCode = setExitCode(err) } return err } if len(failures) > 0 { - exitCode = 125 + for _, err := range failures { + exitCode = setExitCode(err) + } } return printCmdResults(ok, failures) diff --git a/cmd/podman/rmi.go b/cmd/podman/rmi.go index 57e78c34a..3f621116e 100644 --- a/cmd/podman/rmi.go +++ b/cmd/podman/rmi.go @@ -74,6 +74,7 @@ func rmiCmd(c *cliconfig.RmiValues) error { fmt.Printf("A container associated with containers/storage, i.e. via Buildah, CRI-O, etc., may be associated with this image: %-12.12s\n", img.ID()) } if !adapter.IsImageNotFound(err) { + exitCode = 2 failureCnt++ } if lastError != nil { |