diff options
| author | rtkay123 <dev@kanjala.com> | 2025-11-23 11:10:45 +0200 |
|---|---|---|
| committer | rtkay123 <dev@kanjala.com> | 2025-11-23 11:10:45 +0200 |
| commit | 432a5061c0b910821635825021a37f798e0ce26c (patch) | |
| tree | 08346d3a30debd326d2bcf30efc55017362e8d50 /crates | |
| parent | f9af6bf27fb448a64fdfeb219e4d2302938c5a1a (diff) | |
| download | sellershut-432a5061c0b910821635825021a37f798e0ce26c.tar.bz2 sellershut-432a5061c0b910821635825021a37f798e0ce26c.zip | |
feat(config): read from cli
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/sellershut/Cargo.toml | 3 | ||||
| -rw-r--r-- | crates/sellershut/src/config/logging.rs | 37 | ||||
| -rw-r--r-- | crates/sellershut/src/config/mod.rs | 28 | ||||
| -rw-r--r-- | crates/sellershut/src/main.rs | 13 |
4 files changed, 77 insertions, 4 deletions
diff --git a/crates/sellershut/Cargo.toml b/crates/sellershut/Cargo.toml index 1726be8..9fcf378 100644 --- a/crates/sellershut/Cargo.toml +++ b/crates/sellershut/Cargo.toml @@ -8,9 +8,10 @@ documentation.workspace = true description.workspace = true [dependencies] +activitypub_federation = { workspace = true, features = ["axum"] } anyhow = "1.0.100" axum = { version = "0.8.7", features = ["macros"] } -config = { version = "0.15.19", default-features = false, features = ["toml", "convert_case"] } +clap = { version = "4.5.53", features = ["derive", "env"] } tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "signal"] } tower-http = { version = "0.6.6", features = ["trace", "timeout"] } tracing.workspace = true diff --git a/crates/sellershut/src/config/logging.rs b/crates/sellershut/src/config/logging.rs new file mode 100644 index 0000000..9427573 --- /dev/null +++ b/crates/sellershut/src/config/logging.rs @@ -0,0 +1,37 @@ +use clap::ValueEnum; + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)] +pub enum LogLevel { + /// The "trace" level. + /// + /// Designates very low priority, often extremely verbose, information. + Trace = 0, + /// The "debug" level. + /// + /// Designates lower priority information. + Debug = 1, + /// The "info" level. + /// + /// Designates useful information. + Info = 2, + /// The "warn" level. + /// + /// Designates hazardous situations. + Warn = 3, + /// The "error" level. + /// + /// Designates very serious errors. + Error = 4, +} + +impl From<LogLevel> for tracing::Level { + fn from(value: LogLevel) -> Self { + match value { + LogLevel::Trace => tracing::Level::TRACE, + LogLevel::Debug => tracing::Level::DEBUG, + LogLevel::Info => tracing::Level::INFO, + LogLevel::Warn => tracing::Level::WARN, + LogLevel::Error => tracing::Level::ERROR, + } + } +} diff --git a/crates/sellershut/src/config/mod.rs b/crates/sellershut/src/config/mod.rs new file mode 100644 index 0000000..9ce7b2d --- /dev/null +++ b/crates/sellershut/src/config/mod.rs @@ -0,0 +1,28 @@ +mod logging; + +use std::path::PathBuf; + +use clap::Parser; +use logging::LogLevel; + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +pub struct Cli { + /// Sets the port the server listens on + #[arg(default_value_t = 2210, env = "PORT")] + port: u16, + + /// Sets the port the server listens on + #[arg(short, long, value_enum, env = "LOG_LEVEL", default_value_t = LogLevel::Debug)] + log_level: LogLevel, + + /// Sets a custom config file + #[arg(short, long, value_name = "FILE")] + config: Option<PathBuf>, +} + +impl Cli { + pub fn log_level(&self) -> tracing::Level { + self.log_level.into() + } +} diff --git a/crates/sellershut/src/main.rs b/crates/sellershut/src/main.rs index 22dcb86..9736986 100644 --- a/crates/sellershut/src/main.rs +++ b/crates/sellershut/src/main.rs @@ -1,18 +1,25 @@ +mod config; + use std::time::Duration; use axum::{Router, routing::get}; +use clap::Parser; use tokio::{net::TcpListener, signal}; use tower_http::{timeout::TimeoutLayer, trace::TraceLayer}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] -async fn main()-> anyhow::Result<()> { +async fn main() -> anyhow::Result<()> { + let config = config::Cli::parse(); + dbg!(&config); + tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { format!( - "{}=debug,tower_http=debug,axum=trace", - env!("CARGO_CRATE_NAME") + "{}={},tower_http=debug,axum=trace", + env!("CARGO_CRATE_NAME"), + config.log_level() ) .into() }), |
