use anyhow::Result;
use clap::Parser;
use tracing::{Level, info};
mod config;
mod server;
mod utils;
use config::{Cli, load_configuration};
use server::start_server;
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
init_logging(cli.verbose, cli.quiet)?;
let config = load_configuration(&cli)?;
start_server(config).await
}
fn init_logging(verbose_count: u8, quiet_count: u8) -> Result<()> {
let base_level = 2i8; let adjustment = verbose_count as i8 - quiet_count as i8;
let final_level = (base_level + adjustment).clamp(0, 4);
let level = match final_level {
i8::MIN..=0 => Level::ERROR,
1 => Level::WARN,
2 => Level::INFO,
3 => Level::DEBUG,
4.. => Level::TRACE,
};
tracing_subscriber::fmt()
.with_max_level(level)
.with_target(false)
.with_thread_ids(false)
.with_file(false)
.with_line_number(false)
.compact()
.init();
info!("logging initialized at level: {}", level);
Ok(())
}