Entrypoint called by [`crate::main`]
()
| 44 | |
| 45 | /// Entrypoint called by [`crate::main`] |
| 46 | pub fn main() -> color_eyre::eyre::Result<()> { |
| 47 | let cli = Cli::parse(); |
| 48 | |
| 49 | // redirect all log messages into the [debug::DebugLog] |
| 50 | if has_debug_log(&cli) { |
| 51 | static LOGGER: debug::MessageLogger = debug::MessageLogger; |
| 52 | log::set_logger(&LOGGER) |
| 53 | .map(|()| log::set_max_level(log::LevelFilter::max())) |
| 54 | .unwrap(); |
| 55 | } |
| 56 | |
| 57 | color_eyre::install()?; |
| 58 | cli.color.write_global(); |
| 59 | |
| 60 | if let Some(mut subcommand) = cli.command { |
| 61 | if let Err(error) = subcommand.run() { |
| 62 | eprintln!("{error}"); |
| 63 | // Copied from |
| 64 | // https://doc.rust-lang.org/src/std/backtrace.rs.html#1-504, since it's private |
| 65 | fn backtrace_enabled() -> bool { |
| 66 | match env::var("RUST_LIB_BACKTRACE") { |
| 67 | Ok(s) => s != "0", |
| 68 | Err(_) => match env::var("RUST_BACKTRACE") { |
| 69 | Ok(s) => s != "0", |
| 70 | Err(_) => false, |
| 71 | }, |
| 72 | } |
| 73 | } |
| 74 | if backtrace_enabled() { |
| 75 | eprintln!("{:#}", error.backtrace()); |
| 76 | } |
| 77 | |
| 78 | exit(1) |
| 79 | } |
| 80 | } else { |
| 81 | Cli::command().print_help()?; |
| 82 | } |
| 83 | |
| 84 | Ok(()) |
| 85 | } |
| 86 | |
| 87 | #[derive(Parser, Debug, Clone)] |
| 88 | struct Cli { |
nothing calls this directly
no test coverage detected