Compare commits

..

No commits in common. "9ea146aabfc6425da5dea0a105c4032e06ceb398" and "c81952002fd9d1080e31e0e8c16cf59a3f527c67" have entirely different histories.

3 changed files with 6 additions and 90 deletions

View file

@ -46,14 +46,14 @@ use log;
/// Author: Christoph J. Scherr <software@cscherr.de> /// Author: Christoph J. Scherr <software@cscherr.de>
/// ///
/// ``` /// ```
pub const HELP_TEMPLATE: &str = r"{about-section} pub const HELP_TEMPLATE: &str = r#"{about-section}
{usage-heading} {usage} {usage-heading} {usage}
{all-args}{tab} {all-args}{tab}
{name}: {version} {name}: {version}
Author: {author-with-newline} Author: {author-with-newline}
"; "#;
/// Transform -v and -q flags to some kind of loglevel /// Transform -v and -q flags to some kind of loglevel
/// ///
@ -111,7 +111,7 @@ pub struct VerbosityLevel {
// help = L::verbose_help(), // help = L::verbose_help(),
// long_help = L::verbose_long_help(), // long_help = L::verbose_long_help(),
)] )]
verbose: i8, verbose: u8,
/// make the output less verbose /// make the output less verbose
/// ///
@ -123,37 +123,22 @@ pub struct VerbosityLevel {
global = true, global = true,
conflicts_with = "verbose", conflicts_with = "verbose",
)] )]
quiet: i8, quiet: u8,
} }
impl VerbosityLevel { impl VerbosityLevel {
/// true only if no verbose and no quiet was set (user is using defaults) /// true only if no verbose and no quiet was set (user is using defaults)
#[inline] #[inline]
#[must_use]
#[allow(clippy::missing_const_for_fn)] // the values of self can change
pub fn changed(&self) -> bool { pub fn changed(&self) -> bool {
self.verbose != 0 || self.quiet != 0 self.verbose != 0 || self.quiet != 0
} }
#[inline] #[inline]
fn value(&self) -> i8 { fn value(&self) -> i8 {
Self::level_value(Level::INFO) Self::level_value(Level::INFO) - (self.quiet as i8).min(10) + (self.verbose as i8).min(10)
.saturating_sub((self.quiet).min(10))
.saturating_add((self.verbose).min(10))
} }
/// get the [Level] for that [`VerbosityLevel`] /// get the [Level] for that VerbosityLevel
///
/// # Examples
///
/// ```
/// use libpt_log::Level; // reexport: tracing
/// use libpt_cli::args::VerbosityLevel;
///
/// let verbosity_level = VerbosityLevel::INFO;
/// assert_eq!(verbosity_level.level(), Level::INFO);
/// ```
#[inline] #[inline]
#[must_use]
pub fn level(&self) -> Level { pub fn level(&self) -> Level {
let v = self.value(); let v = self.value();
match v { match v {
@ -179,7 +164,6 @@ 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]
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,
@ -200,72 +184,6 @@ impl VerbosityLevel {
Level::ERROR => 0, Level::ERROR => 0,
} }
} }
/// # Examples
///
/// ```
/// use libpt_log::Level; // reexport: tracing
/// use libpt_cli::args::VerbosityLevel;
///
/// let verbosity_level = VerbosityLevel::TRACE;
/// assert_eq!(verbosity_level.level(), Level::TRACE);
/// ```
pub const TRACE: Self = Self {
verbose: 2,
quiet: 0,
};
/// # Examples
///
/// ```
/// use libpt_log::Level; // reexport: tracing
/// use libpt_cli::args::VerbosityLevel;
///
/// let verbosity_level = VerbosityLevel::DEBUG;
/// assert_eq!(verbosity_level.level(), Level::DEBUG);
/// ```
pub const DEBUG: Self = Self {
verbose: 1,
quiet: 0,
};
/// # Examples
///
/// ```
/// use libpt_log::Level; // reexport: tracing
/// use libpt_cli::args::VerbosityLevel;
///
/// let verbosity_level = VerbosityLevel::INFO;
/// assert_eq!(verbosity_level.level(), Level::INFO);
/// ```
pub const INFO: Self = Self {
verbose: 0,
quiet: 0,
};
/// # Examples
///
/// ```
/// use libpt_log::Level; // reexport: tracing
/// use libpt_cli::args::VerbosityLevel;
///
/// let verbosity_level = VerbosityLevel::WARN;
/// assert_eq!(verbosity_level.level(), Level::WARN);
/// ```
pub const WARN: Self = Self {
verbose: 0,
quiet: 1,
};
/// # Examples
///
/// ```
/// use libpt_log::Level; // reexport: tracing
/// use libpt_cli::args::VerbosityLevel;
///
/// let verbosity_level = VerbosityLevel::ERROR;
/// assert_eq!(verbosity_level.level(), Level::ERROR);
/// ```
pub const ERROR: Self = Self {
verbose: 0,
quiet: 2,
};
} }
impl std::fmt::Debug for VerbosityLevel { impl std::fmt::Debug for VerbosityLevel {

View file

@ -1,4 +1,3 @@
#![warn(clippy::pedantic, clippy::style, clippy::nursery)]
pub mod args; pub mod args;
pub mod printing; pub mod printing;
pub mod repl; pub mod repl;

View file

@ -5,7 +5,6 @@
//! //!
//! `pt` is a project consisting of multiple smaller crates, all bundled together in this //! `pt` is a project consisting of multiple smaller crates, all bundled together in this
//! "main crate". Most crates will only show up if you activate their feature. //! "main crate". Most crates will only show up if you activate their feature.
#![warn(clippy::pedantic, clippy::style, clippy::nursery)]
#[cfg_attr(docsrs, doc(cfg(feature = "full")))] #[cfg_attr(docsrs, doc(cfg(feature = "full")))]
#[cfg(feature = "bintols")] #[cfg(feature = "bintols")]
pub use libpt_bintols as bintols; pub use libpt_bintols as bintols;