1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mod error;
pub mod report;

pub use error::{CliError, Error, ErrorWrap};

pub type Result<T, E = Error> = core::result::Result<T, E>;

pub trait ExitCode {
    fn exit_code(&self) -> i32 {
        exitcode::SOFTWARE
    }
}

impl ExitCode for anyhow::Error {
    fn exit_code(&self) -> i32 {
        if let Some(err) = self.downcast_ref::<error::CliError>() {
            err.exit_code()
        } else if let Some(err) = self.downcast_ref::<error::Error>() {
            err.exit_code()
        } else {
            exitcode::SOFTWARE
        }
    }
}