Skip to main content

cargo_airbender/
main.rs

1#![doc = include_str!("../README.md")]
2// TODO: This feature is not really required, but added as a workaround for:
3// https://github.com/rust-lang/rust/issues/141492
4// See also:
5// - https://github.com/rust-lang/rust/issues/144690
6// - https://github.com/rust-lang/rust/issues/133199
7#![cfg_attr(doc, feature(generic_const_exprs))]
8
9mod cli;
10mod commands;
11mod error;
12mod input;
13mod ui;
14
15use crate::error::{CliError, Result};
16
17fn main() {
18    let cli = cli::Cli::parse_for_cargo();
19
20    if let Err(err) = init_tracing() {
21        ui::render_error(&err);
22        std::process::exit(1);
23    }
24
25    if let Err(err) = commands::run(cli) {
26        ui::render_error(&err);
27        std::process::exit(1);
28    }
29}
30
31fn init_tracing() -> Result<()> {
32    let filter = tracing_subscriber::EnvFilter::try_from_default_env()
33        .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn"));
34
35    tracing_subscriber::fmt()
36        .with_env_filter(filter)
37        .with_target(false)
38        .without_time()
39        .try_init()
40        .map_err(|err| {
41            CliError::with_source(
42                "failed to initialize tracing subscriber",
43                anyhow::Error::from_boxed(err),
44            )
45            .with_hint("set RUST_LOG=<level> (for example `RUST_LOG=info`) to inspect backend logs")
46        })?;
47
48    Ok(())
49}