Skip to content

Commit

Permalink
docs: Clarify role of each API item
Browse files Browse the repository at this point in the history
Inspired by clap-rs#77
  • Loading branch information
epage committed Dec 15, 2023
1 parent c5c21e5 commit a06396f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@
//! }
//! ```
//!
//! Or implement [`LogLevel`] yourself for more control.
//! Or implement out [`LogLevel`] trait to customize the default log level and help output.

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

pub use log::Level;
pub use log::LevelFilter;

/// Logging flags to `#[command(flatte)]` into your CLI
#[derive(clap::Args, Debug, Clone, Default)]
pub struct Verbosity<L: LogLevel = ErrorLevel> {
#[arg(
Expand Down Expand Up @@ -151,6 +152,7 @@ impl<L: LogLevel> fmt::Display for Verbosity<L> {
}
}

/// Customize the default log-level and associated help
pub trait LogLevel {
fn default() -> Option<log::Level>;

Expand All @@ -171,6 +173,7 @@ pub trait LogLevel {
}
}

/// Default to [`log::Level::Error`]
#[derive(Copy, Clone, Debug, Default)]
pub struct ErrorLevel;

Expand All @@ -180,6 +183,7 @@ impl LogLevel for ErrorLevel {
}
}

/// Default to [`log::Level::Warn`]
#[derive(Copy, Clone, Debug, Default)]
pub struct WarnLevel;

Expand All @@ -189,6 +193,7 @@ impl LogLevel for WarnLevel {
}
}

/// Default to [`log::Level::Info`]
#[derive(Copy, Clone, Debug, Default)]
pub struct InfoLevel;

Expand Down

0 comments on commit a06396f

Please sign in to comment.