use zesven::Error;
pub const SUCCESS: i32 = 0;
pub const WARNING: i32 = 1;
pub const FATAL_ERROR: i32 = 2;
pub const BAD_ARCHIVE: i32 = 3;
pub const WRONG_PASSWORD: i32 = 4;
pub const IO_ERROR: i32 = 5;
pub const USER_INTERRUPT: i32 = 130;
pub const BAD_ARGS: i32 = 255;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)] pub enum ExitCode {
Success,
Warning,
FatalError,
BadArchive,
WrongPassword,
IoError,
UserInterrupt,
BadArgs,
}
impl ExitCode {
pub fn code(self) -> i32 {
match self {
Self::Success => SUCCESS,
Self::Warning => WARNING,
Self::FatalError => FATAL_ERROR,
Self::BadArchive => BAD_ARCHIVE,
Self::WrongPassword => WRONG_PASSWORD,
Self::IoError => IO_ERROR,
Self::UserInterrupt => USER_INTERRUPT,
Self::BadArgs => BAD_ARGS,
}
}
}
pub fn error_to_exit_code(error: &Error) -> ExitCode {
match error {
Error::Io(_) => ExitCode::IoError,
Error::InvalidFormat(_) | Error::CorruptHeader { .. } => ExitCode::BadArchive,
Error::WrongPassword { .. } => ExitCode::WrongPassword,
Error::CrcMismatch { .. } => ExitCode::BadArchive,
Error::UnsupportedMethod { .. } => ExitCode::BadArchive,
Error::UnsupportedFeature { .. } => ExitCode::BadArchive,
Error::PathTraversal { .. } => ExitCode::FatalError,
Error::ResourceLimitExceeded(_) => ExitCode::FatalError,
Error::InvalidArchivePath(_) => ExitCode::BadArgs,
Error::CryptoError(_) => ExitCode::FatalError,
Error::VolumeMissing { .. } => ExitCode::IoError,
Error::VolumeCorrupted { .. } => ExitCode::BadArchive,
Error::IncompleteArchive { .. } => ExitCode::BadArchive,
Error::Cancelled => ExitCode::UserInterrupt,
#[cfg(feature = "regex")]
Error::InvalidRegex { .. } => ExitCode::BadArgs,
_ => ExitCode::FatalError,
}
}