generated from PlexSheep/baserepo
idk why this isn't in master yet #94
|
@ -16,8 +16,8 @@ categories.workspace = true
|
||||||
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
|
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["log"]
|
default = []
|
||||||
log = ["dep:libpt-log", "dep:log"]
|
log = ["dep:log"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
@ -29,7 +29,7 @@ embed-doc-image = "0.1.4"
|
||||||
exitcode = "1.1.2"
|
exitcode = "1.1.2"
|
||||||
human-panic = "2.0.0"
|
human-panic = "2.0.0"
|
||||||
indicatif = "0.17.8"
|
indicatif = "0.17.8"
|
||||||
libpt-log = { workspace = true, optional = true }
|
libpt-log = { workspace = true, optional = false }
|
||||||
log = { version = "0.4.21", optional = true }
|
log = { version = "0.4.21", optional = true }
|
||||||
shlex = "1.3.0"
|
shlex = "1.3.0"
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! Utilities for parsing options and arguments on the start of a CLI application
|
//! Utilities for parsing options and arguments on the start of a CLI application
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
#[cfg(feature = "log")]
|
|
||||||
use libpt_log::Level;
|
use libpt_log::Level;
|
||||||
#[cfg(feature = "log")]
|
#[cfg(feature = "log")]
|
||||||
use log;
|
use log;
|
||||||
|
@ -100,7 +99,6 @@ Author: {author-with-newline}
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Parser, Clone, PartialEq, Eq, Hash)]
|
#[derive(Parser, Clone, PartialEq, Eq, Hash)]
|
||||||
#[cfg(feature = "log")]
|
|
||||||
pub struct VerbosityLevel {
|
pub struct VerbosityLevel {
|
||||||
/// make the output more verbose
|
/// make the output more verbose
|
||||||
#[arg(
|
#[arg(
|
||||||
|
@ -135,6 +133,7 @@ impl VerbosityLevel {
|
||||||
self.verbose != 0 || self.quiet != 0
|
self.verbose != 0 || self.quiet != 0
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
fn value(&self) -> i8 {
|
fn value(&self) -> i8 {
|
||||||
Self::level_value(Level::INFO)
|
Self::level_value(Level::INFO)
|
||||||
.saturating_sub((self.quiet).min(10))
|
.saturating_sub((self.quiet).min(10))
|
||||||
|
@ -180,6 +179,7 @@ impl VerbosityLevel {
|
||||||
/// [None] means that absolutely no output is wanted (completely quiet)
|
/// [None] means that absolutely no output is wanted (completely quiet)
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[cfg(feature = "log")]
|
||||||
pub fn level_for_log_crate(&self) -> log::Level {
|
pub fn level_for_log_crate(&self) -> log::Level {
|
||||||
match self.level() {
|
match self.level() {
|
||||||
Level::TRACE => log::Level::Trace,
|
Level::TRACE => log::Level::Trace,
|
||||||
|
@ -191,7 +191,8 @@ impl VerbosityLevel {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn level_value(level: Level) -> i8 {
|
#[must_use]
|
||||||
|
const fn level_value(level: Level) -> i8 {
|
||||||
match level {
|
match level {
|
||||||
Level::TRACE => 4,
|
Level::TRACE => 4,
|
||||||
Level::DEBUG => 3,
|
Level::DEBUG => 3,
|
||||||
|
@ -274,3 +275,9 @@ impl std::fmt::Debug for VerbosityLevel {
|
||||||
write!(f, "{:?}", self.level())
|
write!(f, "{:?}", self.level())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for VerbosityLevel {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::INFO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue