From e5de2d3f208776ceb8d65581ce3fdab8f4955d85 Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Sun, 28 May 2023 22:57:07 +1000 Subject: [PATCH] Add cli arg for log level to playground (#343) ## Description Fixes #305 `cargo run -- -l trace` Uses `Level`'s `FromStr` impl, which accepts numbers 1-5 or case-insensitive level names. Default level is `Level::DEBUG` --- tools/playground/Cargo.toml | 1 + tools/playground/src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/playground/Cargo.toml b/tools/playground/Cargo.toml index 42ec02d..c1c5c5d 100644 --- a/tools/playground/Cargo.toml +++ b/tools/playground/Cargo.toml @@ -5,6 +5,7 @@ edition.workspace = true [dependencies] anyhow = "1.0.65" +clap = { version = "4", features = ["derive"] } glam = "0.23.0" tracing = "0.1.37" tracing-subscriber = "0.3.16" diff --git a/tools/playground/src/main.rs b/tools/playground/src/main.rs index b1498cb..6d9a94f 100644 --- a/tools/playground/src/main.rs +++ b/tools/playground/src/main.rs @@ -16,6 +16,7 @@ clippy::dbg_macro )] +use clap::Parser; use tracing::Level; use valence::app::App; @@ -23,9 +24,17 @@ use valence::app::App; mod extras; mod playground; +#[derive(Parser)] +struct Args { + #[arg(short, default_value_t = Level::DEBUG)] + log_level: Level, +} + fn main() { + let args = Args::parse(); + tracing_subscriber::fmt() - .with_max_level(Level::DEBUG) + .with_max_level(args.log_level) .init(); let mut app = App::new();