use std::sync::Arc;
use clap::Parser;
use tracing::info;
use crate::bootstrap;
use crate::presentation::cli::dispatch::route_command;
use crate::presentation::cli::dispatch::ExecutionContext;
use crate::presentation::cli::error::handle_error;
use crate::presentation::cli::Cli;
pub async fn run() {
let cli = Cli::parse();
let logging_config = cli.global.logging_config();
bootstrap::logging::init_subscriber(logging_config);
info!(
app = "torrust-tracker-deployer",
version = env!("CARGO_PKG_VERSION"),
log_dir = %cli.global.log_dir.display(),
log_file_format = ?cli.global.log_file_format,
log_stderr_format = ?cli.global.log_stderr_format,
log_output = ?cli.global.log_output,
"Application started"
);
let container = Arc::new(bootstrap::Container::new(
cli.global.verbosity_level(),
&cli.global.working_dir,
));
let context = ExecutionContext::new(container, cli.global.clone());
match cli.command {
Some(command) => {
if let Err(e) = route_command(command, &cli.global.working_dir, &context).await {
handle_error(&e, &context.user_output());
std::process::exit(1);
}
}
None => {
bootstrap::help::display_getting_started();
}
}
info!("Application finished");
}