From 71da10478f0ee4658b7043ecc1fa97707ff9dfb6 Mon Sep 17 00:00:00 2001 From: Said Nizamutdinov Date: Fri, 17 Apr 2026 10:45:51 +0300 Subject: [PATCH] Add tracing with --verbose and --quiet global flags Adds tracing + tracing-subscriber dependencies and wires up an init_tracing() helper that maps --verbose to debug level and --quiet to error-only. Default level is warn. Mirrors the gitlab-cli pattern. Co-Authored-By: Claude Opus 4.6 --- Cargo.lock | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 2 + src/cli.rs | 8 ++++ src/main.rs | 18 ++++++++ 4 files changed, 148 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2e1afb..c240e5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "1.0.0" @@ -211,7 +220,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -591,6 +600,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.185" @@ -636,6 +651,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + [[package]] name = "memchr" version = "2.8.0" @@ -669,6 +693,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "once_cell" version = "1.21.4" @@ -851,6 +884,23 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + [[package]] name = "reqwest" version = "0.12.28" @@ -944,7 +994,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -1065,6 +1115,15 @@ dependencies = [ "serde", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -1162,6 +1221,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + [[package]] name = "tinystr" version = "0.8.3" @@ -1288,9 +1356,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.36" @@ -1298,6 +1378,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -1360,6 +1470,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + [[package]] name = "want" version = "0.3.1" @@ -1647,6 +1763,8 @@ dependencies = [ "serde_json", "thiserror", "tokio", + "tracing", + "tracing-subscriber", "youtrack-client-api", ] diff --git a/Cargo.toml b/Cargo.toml index 5c427a9..0874d95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,5 @@ comfy-table = "7.1" futures = "0.3" rpassword = "7.4" thiserror = "2" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] } diff --git a/src/cli.rs b/src/cli.rs index 0ac042a..a44c55e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -129,6 +129,14 @@ pub struct Cli { #[arg(long, global = true)] pub json: bool, + /// Show config-source details and enable debug logging. + #[arg(long, global = true, conflicts_with = "quiet", help_heading = "Global Options")] + pub verbose: bool, + + /// Reduce logging to errors only. + #[arg(long, global = true, conflicts_with = "verbose", help_heading = "Global Options")] + pub quiet: bool, + #[command(subcommand)] pub command: Command, } diff --git a/src/main.rs b/src/main.rs index aece29c..10bc88a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ mod output; use std::process::ExitCode; use clap::Parser; +use tracing_subscriber::EnvFilter; use crate::cli::{Cli, Command, CommentCommand, IssueCommand}; use crate::error::CliResult; @@ -16,6 +17,7 @@ use crate::output::OutputMode; #[tokio::main] async fn main() -> ExitCode { let cli = Cli::parse(); + init_tracing(cli.verbose, cli.quiet); match run(cli).await { Ok(()) => ExitCode::SUCCESS, Err(err) => { @@ -71,3 +73,19 @@ async fn run(cli: Cli) -> CliResult<()> { }, } } + +fn init_tracing(verbose: bool, quiet: bool) { + let level = if quiet { + "error" + } else if verbose { + "debug" + } else { + "warn" + }; + + let _ = tracing_subscriber::fmt() + .with_target(false) + .without_time() + .with_env_filter(EnvFilter::new(level)) + .try_init(); +}