From 1568b7e08a8dd1de2bc0344f67f380f9b5efe4aa Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 22 Dec 2024 15:58:04 +0000 Subject: [PATCH] feat: add support for tokio-console --- Cargo.toml | 3 ++- mise.toml | 1 + src/lib.rs | 11 ++++++++++- src/tests/check.rs | 3 +++ src/tests/init.rs | 2 ++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 30aeb3a..a4510a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,10 +22,11 @@ rand = "0.8" reqwest = { version = "0.12" , features = ["multipart", "stream"]} serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tokio = { version = "1.41", features = ["full"] } +tokio = { version = "1.41", features = ["full", "tracing"] } toml = "0.8" tracing = "0.1" tracing-subscriber = "0.3" +console-subscriber = "0.4" [dev-dependencies] assert2 = "0.3" diff --git a/mise.toml b/mise.toml index 24be325..9a4a7ae 100644 --- a/mise.toml +++ b/mise.toml @@ -1,3 +1,4 @@ [tools] "cargo:cargo-llvm-cov" = "latest" "cargo:cargo-tarpaulin" = "latest" +"cargo:tokio-console" = "latest" diff --git a/src/lib.rs b/src/lib.rs index 0ba2002..4c212df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,8 @@ const NAME: &str = "trello-to-deck"; pub struct Commands { #[clap(long, action = clap::ArgAction::SetTrue)] pub log: bool, + #[clap(long, action = clap::ArgAction::SetTrue)] + pub tokio_console: bool, #[clap(subcommand)] pub command: Command, } @@ -95,7 +97,14 @@ impl FullCtx { #[cfg_attr(test, mutants::skip)] pub async fn run(ctx: &Ctx, commands: &Commands) -> color_eyre::Result<()> { - if commands.log { + if commands.tokio_console { + use tracing_subscriber::prelude::*; + let console_layer = console_subscriber::spawn(); + tracing_subscriber::registry() + .with(console_layer) + .with(tracing_subscriber::fmt::layer()) + .init(); + } else if commands.log { tracing::subscriber::set_global_default( tracing_subscriber::FmtSubscriber::builder() .with_max_level(tracing::Level::TRACE) diff --git a/src/tests/check.rs b/src/tests/check.rs index ce82476..c848ffd 100644 --- a/src/tests/check.rs +++ b/src/tests/check.rs @@ -7,12 +7,14 @@ use http::StatusCode; fn test_commands_log_flag() { let commands = Commands { log: true, + tokio_console: false, command: Command::Init, }; assert!(commands.log); let commands = Commands { log: false, + tokio_console: false, command: Command::Init, }; assert!(!commands.log); @@ -132,6 +134,7 @@ async fn test_run() -> Result<()> { let commands = Commands { log: false, + tokio_console: false, command: Command::Check, }; diff --git a/src/tests/init.rs b/src/tests/init.rs index 04c87b7..dee32bc 100644 --- a/src/tests/init.rs +++ b/src/tests/init.rs @@ -11,6 +11,7 @@ async fn when_file_does_not_exist_should_create() { let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer()); let commands = Commands { log: false, + tokio_console: false, command: Command::Init, }; @@ -34,6 +35,7 @@ async fn when_file_exists_should_err() { let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer()); let commands = Commands { log: false, + tokio_console: false, command: Command::Init, };