From ce65d9eeafcd1f9d5c3adef1c9b1af6258ee711a Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 1 Feb 2026 13:33:07 +0200 Subject: feat: conn to db --- src/config/cli.rs | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/config/cli.rs (limited to 'src/config/cli.rs') diff --git a/src/config/cli.rs b/src/config/cli.rs new file mode 100644 index 0000000..dab7216 --- /dev/null +++ b/src/config/cli.rs @@ -0,0 +1,101 @@ +use std::path::PathBuf; + +use clap::Parser; +use url::Url; + +use crate::config::{logging::LogLevel, port::port_in_range}; + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None, name = env!("CARGO_PKG_NAME"))] +pub struct Cli { + /// Sets the port the server listens on + #[arg(short, long, default_value = "2210", env = "PORT", value_parser = port_in_range)] + pub port: Option, + + /// Server's domain + #[arg(short, long, default_value = "localhost", env = "DOMAIN")] + pub domain: Option, + + /// Sets a custom config file + #[arg(short, long, value_name = "FILE")] + pub config: Option, + + /// Sets the application log level + #[arg(short, long, value_enum, env = "LOG_LEVEL", default_value = "debug")] + pub log_level: Option, + + /// Request timeout duration (in seconds) + #[arg(short, long, env = "TIMEOUT_SECONDS", default_value = "10")] + pub timeout_duration: Option, + + /// Users database connection string + #[arg( + long, + env = "USERS_DATABASE_URL", + default_value = "postgres://postgres:password@localhost:5432/sellershut" + )] + pub db: Option, + + /// Server's system name + #[arg(short, long, default_value = "sellershut", env = "SYSTEM_NAME")] + pub system_name: Option, + + /// Server's system name + #[arg(short, long, default_value = "prod", env = "SYSTEM_NAME")] + pub environment: Option, + + /// Oauth optionas + #[command(flatten)] + pub oauth: Option, +} + +#[derive(Debug, Clone, Parser)] +pub struct OAuth { + #[cfg(feature = "oauth-discord")] + #[command(flatten)] + discord: DiscordOauth, + #[arg(long)] + oauth_redirect_url: Option, +} + +#[cfg(feature = "oauth-discord")] +#[derive(Debug, Clone, Parser)] +pub struct DiscordOauth { + #[arg(long)] + discord_client_id: Option, + #[arg(long)] + discord_client_secret: Option, + #[arg(long)] + discord_token_url: Option, + #[arg(long)] + discord_auth_url: Option, +} + +#[cfg(test)] +impl Default for Cli { + fn default() -> Self { + let url = Url::parse("postgres://postgres:password@localhost:5432/sellershut").ok(); + Self { + port: Default::default(), + config: Default::default(), + log_level: Default::default(), + timeout_duration: Some(10), + domain: Default::default(), + system_name: Default::default(), + environment: Default::default(), + oauth: None, + db: url, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn verify_cli() { + use clap::CommandFactory; + Cli::command().debug_assert(); + } +} -- cgit v1.2.3