diff options
| author | rtkay123 <dev@kanjala.com> | 2026-02-01 13:33:07 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2026-02-01 13:33:07 +0200 |
| commit | ce65d9eeafcd1f9d5c3adef1c9b1af6258ee711a (patch) | |
| tree | 953f6c49f8affd667ec740a949b2d93f82b7d31b /src/config/cli.rs | |
| parent | 6a9d21bc87f8a738e14f27a1305bf04d0c4b7a0c (diff) | |
| download | sellershut-ce65d9eeafcd1f9d5c3adef1c9b1af6258ee711a.tar.bz2 sellershut-ce65d9eeafcd1f9d5c3adef1c9b1af6258ee711a.zip | |
feat: conn to db
Diffstat (limited to 'src/config/cli.rs')
| -rw-r--r-- | src/config/cli.rs | 101 |
1 files changed, 101 insertions, 0 deletions
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<u16>, + + /// Server's domain + #[arg(short, long, default_value = "localhost", env = "DOMAIN")] + pub domain: Option<String>, + + /// Sets a custom config file + #[arg(short, long, value_name = "FILE")] + pub config: Option<PathBuf>, + + /// Sets the application log level + #[arg(short, long, value_enum, env = "LOG_LEVEL", default_value = "debug")] + pub log_level: Option<LogLevel>, + + /// Request timeout duration (in seconds) + #[arg(short, long, env = "TIMEOUT_SECONDS", default_value = "10")] + pub timeout_duration: Option<u64>, + + /// Users database connection string + #[arg( + long, + env = "USERS_DATABASE_URL", + default_value = "postgres://postgres:password@localhost:5432/sellershut" + )] + pub db: Option<Url>, + + /// Server's system name + #[arg(short, long, default_value = "sellershut", env = "SYSTEM_NAME")] + pub system_name: Option<String>, + + /// Server's system name + #[arg(short, long, default_value = "prod", env = "SYSTEM_NAME")] + pub environment: Option<String>, + + /// Oauth optionas + #[command(flatten)] + pub oauth: Option<OAuth>, +} + +#[derive(Debug, Clone, Parser)] +pub struct OAuth { + #[cfg(feature = "oauth-discord")] + #[command(flatten)] + discord: DiscordOauth, + #[arg(long)] + oauth_redirect_url: Option<Url>, +} + +#[cfg(feature = "oauth-discord")] +#[derive(Debug, Clone, Parser)] +pub struct DiscordOauth { + #[arg(long)] + discord_client_id: Option<String>, + #[arg(long)] + discord_client_secret: Option<String>, + #[arg(long)] + discord_token_url: Option<Url>, + #[arg(long)] + discord_auth_url: Option<Url>, +} + +#[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(); + } +} |
