use std::path::Path; use clap::Parser; use figment::{ Figment, providers::{Env, Format, Json, Toml}, }; use tracing::{Level, event}; mod args; use crate::args::{ActionType, ArgsError, CommandArgs}; mod config; mod error; use crate::error::CommandError; #[tokio::main] async fn main() -> Result<(), CommandError> { let args = CommandArgs::parse(); let figment = Figment::new() .admerge(Json::file("config.json")) .admerge(Toml::file("config.toml")); let config: config::CommandConfig = match &args.config { None => figment, Some(f) => { let file = Path::new(&f); match file.extension().and_then(|e| e.to_str()) { Some("toml") => Ok(figment.admerge(Toml::file(file))), Some("json") => Ok(figment.admerge(Json::file(file))), _ => Err(ArgsError::InvalidConfigExtension( file.extension().and_then(|e| e.to_str().map(String::from)), )), } }?, } .admerge(Env::prefixed("APP_")) .extract()?; match &args.action { ActionType::Serve(serve_args) => { tracing_subscriber::fmt() .with_max_level(serve_args.log_level) .init(); event!(Level::ERROR, "error"); event!(Level::WARN, "warn"); event!(Level::INFO, "info"); event!(Level::DEBUG, "debug"); event!(Level::TRACE, "trace"); println!("{:#?}", args); println!("{:#?}", config); println!("{:#?}", config.port.ports); } }; println!("{}", CommandError::InvalidArgument(ArgsError::InvalidConfigExtension(Some(String::from("txt"))))); Ok(()) }