cmd: Move exit status codes to separate package

Signal handling by the `atexit` package needs acceess to
`exitCodeUncategorizedError`. With this change all exit status values
are moved to a dedicated package so that they can be reused.

Signed-off-by: Michael Hanselmann <public@hansmi.ch>
This commit is contained in:
Michael Hanselmann
2021-07-05 23:48:57 +02:00
committed by Nick Craig-Wood
parent ba5c559fec
commit cf19073ac9
2 changed files with 36 additions and 23 deletions

View File

@@ -37,6 +37,7 @@ import (
"github.com/rclone/rclone/fs/rc/rcserver"
"github.com/rclone/rclone/lib/atexit"
"github.com/rclone/rclone/lib/buildinfo"
"github.com/rclone/rclone/lib/exitcode"
"github.com/rclone/rclone/lib/random"
"github.com/rclone/rclone/lib/terminal"
"github.com/spf13/cobra"
@@ -60,19 +61,6 @@ var (
errorTooManyArguments = errors.New("too many arguments")
)
const (
exitCodeSuccess = iota
exitCodeUsageError
exitCodeUncategorizedError
exitCodeDirNotFound
exitCodeFileNotFound
exitCodeRetryError
exitCodeNoRetryError
exitCodeFatalError
exitCodeTransferExceeded
exitCodeNoFilesTransferred
)
// ShowVersion prints the version to stdout
func ShowVersion() {
osVersion, osKernel := buildinfo.GetOSVersion()
@@ -484,31 +472,31 @@ func resolveExitCode(err error) {
if err == nil {
if ci.ErrorOnNoTransfer {
if accounting.GlobalStats().GetTransfers() == 0 {
os.Exit(exitCodeNoFilesTransferred)
os.Exit(exitcode.NoFilesTransferred)
}
}
os.Exit(exitCodeSuccess)
os.Exit(exitcode.Success)
}
_, unwrapped := fserrors.Cause(err)
switch {
case unwrapped == fs.ErrorDirNotFound:
os.Exit(exitCodeDirNotFound)
os.Exit(exitcode.DirNotFound)
case unwrapped == fs.ErrorObjectNotFound:
os.Exit(exitCodeFileNotFound)
os.Exit(exitcode.FileNotFound)
case unwrapped == errorUncategorized:
os.Exit(exitCodeUncategorizedError)
os.Exit(exitcode.UncategorizedError)
case unwrapped == accounting.ErrorMaxTransferLimitReached:
os.Exit(exitCodeTransferExceeded)
os.Exit(exitcode.TransferExceeded)
case fserrors.ShouldRetry(err):
os.Exit(exitCodeRetryError)
os.Exit(exitcode.RetryError)
case fserrors.IsNoRetryError(err):
os.Exit(exitCodeNoRetryError)
os.Exit(exitcode.NoRetryError)
case fserrors.IsFatalError(err):
os.Exit(exitCodeFatalError)
os.Exit(exitcode.FatalError)
default:
os.Exit(exitCodeUsageError)
os.Exit(exitcode.UsageError)
}
}