aboutsummaryrefslogtreecommitdiffstats
path: root/lib/warden-core/src/config/cli/mod.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-03-29 16:15:54 +0200
committerrtkay123 <dev@kanjala.com>2026-03-29 16:15:54 +0200
commit57c4a5251c30d3dc2b78059fd208d8948d999056 (patch)
tree43d86334ad8c08305b9cadda3a524016e0ea4cfc /lib/warden-core/src/config/cli/mod.rs
parentc02a5a74d637bab34dc85a0f8a6cfd2a69fd6597 (diff)
downloadwarden-57c4a5251c30d3dc2b78059fd208d8948d999056.tar.bz2
warden-57c4a5251c30d3dc2b78059fd208d8948d999056.zip
refactor: move config to core
Diffstat (limited to 'lib/warden-core/src/config/cli/mod.rs')
-rw-r--r--lib/warden-core/src/config/cli/mod.rs85
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/warden-core/src/config/cli/mod.rs b/lib/warden-core/src/config/cli/mod.rs
new file mode 100644
index 0000000..36f6bf0
--- /dev/null
+++ b/lib/warden-core/src/config/cli/mod.rs
@@ -0,0 +1,85 @@
+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<PathBuf>,
+ #[command(flatten)]
+ pub server: Server,
+ #[command(subcommand)]
+ #[serde(skip)]
+ pub command: Option<Commands>,
+ #[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<u16>,
+ /// Runtime environment
+ #[arg(short, long, value_name = "ENV", default_value = "prod", env = "ENV")]
+ pub environment: Option<CliEnvironment>,
+ /// Log Level
+ #[arg(long, value_name = "LOG_LEVEL", env = "LOG_LEVEL")]
+ pub log_level: Option<String>,
+ /// Log file directory (defaults to temp_dir)
+ #[arg(long, value_name = "DIR", env = "LOGS_DIR")]
+ pub log_dir: Option<PathBuf>,
+ /// Request timeout duration in seconds
+ #[arg(
+ long,
+ value_name = "TIMEOUT_DURATION",
+ env = "TIMEOUT_DURATION_SECS",
+ default_value = "5"
+ )]
+ pub timeout_secs: Option<u64>,
+}
+
+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",
+ 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,
+}