Trait narrate::ExitCode

source ·
pub trait ExitCode: Sealed {
    // Provided method
    fn exit_code(&self) -> i32 { ... }
}
Expand description

Provide exit_code method for CliError. Intended to be passed to std::process::exit.

Provided Methods§

source

fn exit_code(&self) -> i32

CLI application exit code

Examples found in repository?
examples/lazy_wrap.rs (line 24)
18
19
20
21
22
23
24
25
26
fn main() {
    let path = PathBuf::from("/not/an/exsisting/file");
    let res = run(path);

    if let Err(ref err) = res {
        report::err_full(err);
        std::process::exit(err.exit_code());
    }
}
More examples
Hide additional examples
examples/wrap_report_exit.rs (line 15)
8
9
10
11
12
13
14
15
16
17
fn main() {
    let res = config_error()
        .wrap(CliError::Config)
        .add_help("See https://docs.example.rs/config for more info");

    if let Err(ref err) = res {
        report::err_full(err);
        std::process::exit(err.exit_code());
    }
}
examples/anyhow_report.rs (line 30)
22
23
24
25
26
27
28
29
30
31
32
fn main() {
    let res = inner_fn().context(CliError::OsErr);

    if let Err(ref err) = res {
        report::anyhow_err_full(err);
        // As the error contains a `CliError`, this code will match its
        // error_code. In this case `71`. If there was no underlying `CliError`,
        // the code will default to `70`.
        std::process::exit(err.exit_code());
    }
}

Implementations on Foreign Types§

source§

impl ExitCode for Error

source§

fn exit_code(&self) -> i32

Implementors§