pub mod database; use std::path::PathBuf; use clap::{Parser, Subcommand, ValueEnum}; use serde::{Deserialize, Serialize}; use crate::config::cli::database::Database; #[derive(Parser, Serialize, Deserialize, Default, Debug)] #[command(version, about, long_about = None)] /// Real-time transaction monitoring pub struct Cli { /// Sets a custom config file #[arg(short, long, value_name = "FILE")] #[serde(skip)] pub config: Option, #[command(flatten)] pub server: Server, #[command(subcommand)] #[serde(skip)] pub command: Option, #[command(flatten)] pub database: Database, } #[derive(Subcommand, Debug)] pub enum Commands { /// Generates a default configuration file Init { /// Path to save the config #[arg(short, long, default_value = "warden.toml")] path: String, }, } #[derive(Parser, Deserialize, Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub struct Server { /// Sets the port that the server listens to #[arg(short, long, value_name = "PORT", env = "PORT", default_value = "2210")] #[arg(value_parser = clap::value_parser!(u16).range(1..=65535))] pub port: Option, /// Runtime environment #[arg(short, long, value_name = "ENV", default_value = "prod", env = "ENV")] pub environment: Option, /// Log Level #[arg(long, value_name = "LOG_LEVEL", env = "LOG_LEVEL")] pub log_level: Option, /// Log file directory (defaults to temp_dir) #[arg(long, value_name = "DIR", env = "LOGS_DIR")] pub log_dir: Option, /// Request timeout duration in seconds #[arg( long, value_name = "TIMEOUT_DURATION", env = "TIMEOUT_DURATION_SECS", default_value = "5" )] pub timeout_secs: Option, } impl Default for Server { fn default() -> Self { Self { port: Some(2210), environment: Default::default(), log_level: Some(format!( "{}=debug,tower_http=debug,axum::rejection=trace,sqlx=warn,debug", env!("CARGO_CRATE_NAME") )), log_dir: Some(std::env::temp_dir()), timeout_secs: Some(5), } } } #[derive(Deserialize, ValueEnum, Serialize, Clone, Copy, Default, Debug)] #[serde(rename_all = "lowercase")] pub enum CliEnvironment { #[default] Dev, Development, Prod, Production, }