1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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,
}
|