refactor: remove 'auto' mode, just specify value via constant for better clap visibility

This commit is contained in:
2025-09-13 11:38:18 -05:00
parent f3861a60c4
commit 79fc931077
3 changed files with 14 additions and 12 deletions

2
Cargo.lock generated
View File

@@ -218,7 +218,7 @@ dependencies = [
[[package]] [[package]]
name = "banner" name = "banner"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "banner" name = "banner"
version = "0.2.1" version = "0.2.2"
edition = "2024" edition = "2024"
default-run = "banner" default-run = "banner"

View File

@@ -29,23 +29,26 @@ mod services;
mod state; mod state;
mod web; mod web;
#[cfg(debug_assertions)]
const DEFAULT_TRACING_FORMAT: TracingFormat = TracingFormat::Pretty;
#[cfg(not(debug_assertions))]
const DEFAULT_TRACING_FORMAT: TracingFormat = TracingFormat::Json;
/// Banner Discord Bot - Course availability monitoring /// Banner Discord Bot - Course availability monitoring
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
struct Args { struct Args {
/// Log formatter to use /// Log formatter to use
#[arg(long, value_enum, default_value_t = LogFormatter::Auto)] #[arg(long, value_enum, default_value_t = DEFAULT_TRACING_FORMAT)]
formatter: LogFormatter, tracing: TracingFormat,
} }
#[derive(clap::ValueEnum, Clone, Debug)] #[derive(clap::ValueEnum, Clone, Debug)]
enum LogFormatter { enum TracingFormat {
/// Use pretty formatter (default in debug mode) /// Use pretty formatter (default in debug mode)
Pretty, Pretty,
/// Use JSON formatter (default in release mode) /// Use JSON formatter (default in release mode)
Json, Json,
/// Auto-select based on build mode (debug=pretty, release=json)
Auto,
} }
async fn update_bot_status(ctx: &Context, app_state: &AppState) -> Result<(), anyhow::Error> { async fn update_bot_status(ctx: &Context, app_state: &AppState) -> Result<(), anyhow::Error> {
@@ -89,10 +92,9 @@ async fn main() {
}); });
// Select formatter based on CLI args // Select formatter based on CLI args
let use_pretty = match args.formatter { let use_pretty = match args.tracing {
LogFormatter::Pretty => true, TracingFormat::Pretty => true,
LogFormatter::Json => false, TracingFormat::Json => false,
LogFormatter::Auto => cfg!(debug_assertions),
}; };
let subscriber: Box<dyn tracing::Subscriber + Send + Sync> = if use_pretty { let subscriber: Box<dyn tracing::Subscriber + Send + Sync> = if use_pretty {