From e6929ad4e70c3671c1df33064042f6538d08400d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 13 Jun 2022 11:24:47 -0500 Subject: [PATCH 1/3] docs: Clarify this is meant to work with 'log' --- README.md | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81b0222..9122002 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# clap-verbosity-flag +# clap-verbosity-flag for `log` [![Documentation](https://img.shields.io/badge/docs-master-blue.svg)][Documentation] ![License](https://img.shields.io/crates/l/clap-verbosity-flag.svg) diff --git a/src/lib.rs b/src/lib.rs index ef2113d..624fea4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! Easily add a `--verbose` flag to CLIs using Structopt +//! Control `log` level with a `--verbose` flag for your CLI //! //! # Examples //! From 3aacc8ce60d00115388e8e3347af7a496112f634 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 13 Jun 2022 11:41:40 -0500 Subject: [PATCH 2/3] docs: Include tracing example --- Cargo.toml | 3 +++ examples/example.rs | 6 ++++++ examples/example_tracing.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 examples/example_tracing.rs diff --git a/Cargo.toml b/Cargo.toml index 416cd8b..7ddb6d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,6 @@ clap = { version = "3.0", default-features = false, features = ["std", "derive"] [dev-dependencies] env_logger = "0.9.0" +tracing = "0.1" +tracing-subscriber = "0.2" +tracing-log = "0.1.3" diff --git a/examples/example.rs b/examples/example.rs index de8e16f..3c24f18 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -14,4 +14,10 @@ fn main() { env_logger::Builder::new() .filter_level(cli.verbose.log_level_filter()) .init(); + + log::error!("Engines exploded"); + log::warn!("Engines smoking"); + log::info!("Engines exist"); + log::debug!("Engine temperature is 200 degrees"); + log::trace!("Engine subsection is 300 degrees"); } diff --git a/examples/example_tracing.rs b/examples/example_tracing.rs new file mode 100644 index 0000000..efc8b65 --- /dev/null +++ b/examples/example_tracing.rs @@ -0,0 +1,34 @@ +use clap::Parser; +use clap_verbosity_flag::Verbosity; + +/// Foo +#[derive(Debug, Parser)] +struct Cli { + #[clap(flatten)] + verbose: Verbosity, +} + +fn main() { + let cli = Cli::parse(); + + tracing_subscriber::fmt() + .with_max_level(convert_filter(cli.verbose.log_level_filter())) + .init(); + + log::error!("Engines exploded"); + log::warn!("Engines smoking"); + log::info!("Engines exist"); + log::debug!("Engine temperature is 200 degrees"); + log::trace!("Engine subsection is 300 degrees"); +} + +fn convert_filter(filter: log::LevelFilter) -> tracing_subscriber::filter::LevelFilter { + match filter { + log::LevelFilter::Off => tracing_subscriber::filter::LevelFilter::OFF, + log::LevelFilter::Error => tracing_subscriber::filter::LevelFilter::ERROR, + log::LevelFilter::Warn => tracing_subscriber::filter::LevelFilter::WARN, + log::LevelFilter::Info => tracing_subscriber::filter::LevelFilter::INFO, + log::LevelFilter::Debug => tracing_subscriber::filter::LevelFilter::DEBUG, + log::LevelFilter::Trace => tracing_subscriber::filter::LevelFilter::TRACE, + } +} From def304766fe3d510aa47a17ba5af669eca5ba3d0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 13 Jun 2022 11:47:20 -0500 Subject: [PATCH 3/3] chore: Bump MSRV to 1.56.0 --- .clippy.toml | 2 +- .github/workflows/ci.yml | 6 +++--- .github/workflows/rust-next.yml | 4 ++-- Cargo.toml | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index fc3ef79..97dd653 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.54.0" # MSRV +msrv = "1.56.0" # MSRV diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb56ab8..483d44a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: No-default features run: cargo test --workspace --no-default-features msrv: - name: "Check MSRV: 1.54.0" + name: "Check MSRV: 1.56.0" runs-on: ubuntu-latest steps: - name: Checkout repository @@ -59,7 +59,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.54.0 # MSRV + toolchain: 1.56.0 # MSRV profile: minimal override: true - uses: Swatinem/rust-cache@v1 @@ -113,7 +113,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.54.0 # MSRV + toolchain: 1.56.0 # MSRV profile: minimal override: true components: clippy diff --git a/.github/workflows/rust-next.yml b/.github/workflows/rust-next.yml index c09fb04..00c8619 100644 --- a/.github/workflows/rust-next.yml +++ b/.github/workflows/rust-next.yml @@ -57,9 +57,9 @@ jobs: strategy: matrix: rust: - - 1.54.0 # MSRV + - 1.56.0 # MSRV - stable - continue-on-error: ${{ matrix.rust != '1.54.0' }} # MSRV + continue-on-error: ${{ matrix.rust != '1.56.0' }} # MSRV runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/Cargo.toml b/Cargo.toml index 7ddb6d1..c049b10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,8 @@ authors = ["Pascal Hertleif "] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-clique/clap-verbosity-flag" readme = "README.md" -edition = "2018" +edition = "2021" +rust-version = "1.56.0" # MSRV include = [ "src/**/*", "Cargo.toml",