Skip to main content

sbox/
app.rs

1use std::process::ExitCode;
2
3use tracing::Level;
4
5use crate::cli::{Cli, Commands};
6use crate::error::SboxError;
7
8pub fn run(cli: Cli) -> Result<ExitCode, SboxError> {
9    init_logging(cli.verbose, cli.quiet)?;
10
11    match &cli.command {
12        Commands::Plan(command) => crate::plan::execute(&cli, command),
13        Commands::Run(command) => crate::exec::execute_run(&cli, command),
14        Commands::Exec(command) => crate::exec::execute_exec(&cli, command),
15        Commands::Init(command) => crate::init::execute(&cli, command),
16        Commands::Shell(command) => crate::shell::execute(&cli, command),
17        Commands::Doctor(command) => crate::doctor::execute(&cli, command),
18        Commands::Clean(command) => crate::clean::execute(&cli, command),
19        Commands::Shim(command) => crate::shim::execute(command),
20    }
21}
22
23fn init_logging(verbose: u8, quiet: bool) -> Result<(), SboxError> {
24    let level = if quiet {
25        Level::ERROR
26    } else {
27        match verbose {
28            0 => Level::INFO,
29            1 => Level::DEBUG,
30            _ => Level::TRACE,
31        }
32    };
33
34    tracing_subscriber::fmt()
35        .with_max_level(level)
36        .with_target(false)
37        .without_time()
38        .try_init()
39        .map_err(|source| SboxError::LoggingInit { source })?;
40
41    Ok(())
42}