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