feat: add support for tokio-console
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 2m50s
Test / build (map[name:stable]) (push) Successful in 2m39s
Release Please / Release-plz (push) Failing after 53s

This commit is contained in:
Paul Campbell 2024-12-22 15:58:04 +00:00
parent 8305715471
commit 1568b7e08a
5 changed files with 18 additions and 2 deletions

View file

@ -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"

View file

@ -1,3 +1,4 @@
[tools]
"cargo:cargo-llvm-cov" = "latest"
"cargo:cargo-tarpaulin" = "latest"
"cargo:tokio-console" = "latest"

View file

@ -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)

View file

@ -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,
};

View file

@ -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,
};