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 Commands::Bootstrap(_) => crate::bootstrap::execute(&cli),
21 Commands::Audit(command) => crate::audit::execute(&cli, command),
22 }
23}
24
25fn init_logging(verbose: u8, quiet: bool) -> Result<(), SboxError> {
26 let level = if quiet {
27 Level::ERROR
28 } else {
29 match verbose {
30 0 => Level::INFO,
31 1 => Level::DEBUG,
32 _ => Level::TRACE,
33 }
34 };
35
36 tracing_subscriber::fmt()
37 .with_max_level(level)
38 .with_target(false)
39 .without_time()
40 .try_init()
41 .map_err(|source| SboxError::LoggingInit { source })?;
42
43 Ok(())
44}