Struct libpt_cli::args::VerbosityLevel
source · pub struct VerbosityLevel { /* private fields */ }Expand description
Transform -v and -q flags to some kind of loglevel
§Example
Include this into your clap derive struct like this:
use libpt_cli::args::VerbosityLevel;
use clap::Parser;
#[derive(Parser, Debug)]
pub struct Opts {
#[command(flatten)]
pub verbose: VerbosityLevel,
#[arg(short, long)]
pub mynum: usize,
}
Get the loglevel like this:
use libpt_log::Level;
fn main() {
let opts = Opts::parse();
// Level might be None if the user wants no output at all.
// for the 'tracing' level:
let level: Level = opts.verbose.level();
}Implementations§
source§impl VerbosityLevel
impl VerbosityLevel
sourcepub fn changed(&self) -> bool
pub fn changed(&self) -> bool
true only if no verbose and no quiet was set (user is using defaults)
sourcepub fn level(&self) -> Level
pub fn level(&self) -> Level
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);Examples found in repository?
examples/cli.rs (line 27)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let cli = Cli::parse();
let _logger = Logger::builder()
.max_level(cli.verbosity.level())
.show_time(false)
.build();
debug!("logger initialized with level: {}", cli.verbosity.level());
if !cli.machine {
let text = cli.text.join(" ");
printing::blockprint(text, console::Color::Green);
} else {
for text in cli.text {
println!("{text}")
}
}
}sourcepub const TRACE: Self = _
pub const TRACE: Self = _
§Examples
use libpt_log::Level; // reexport: tracing
use libpt_cli::args::VerbosityLevel;
let verbosity_level = VerbosityLevel::TRACE;
assert_eq!(verbosity_level.level(), Level::TRACE);sourcepub const DEBUG: Self = _
pub const DEBUG: Self = _
§Examples
use libpt_log::Level; // reexport: tracing
use libpt_cli::args::VerbosityLevel;
let verbosity_level = VerbosityLevel::DEBUG;
assert_eq!(verbosity_level.level(), Level::DEBUG);sourcepub const INFO: Self = _
pub const INFO: Self = _
§Examples
use libpt_log::Level; // reexport: tracing
use libpt_cli::args::VerbosityLevel;
let verbosity_level = VerbosityLevel::INFO;
assert_eq!(verbosity_level.level(), Level::INFO);Trait Implementations§
source§impl Args for VerbosityLevel
impl Args for VerbosityLevel
source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
source§impl Clone for VerbosityLevel
impl Clone for VerbosityLevel
source§fn clone(&self) -> VerbosityLevel
fn clone(&self) -> VerbosityLevel
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl CommandFactory for VerbosityLevel
impl CommandFactory for VerbosityLevel
source§impl Debug for VerbosityLevel
impl Debug for VerbosityLevel
source§impl Default for VerbosityLevel
impl Default for VerbosityLevel
source§impl FromArgMatches for VerbosityLevel
impl FromArgMatches for VerbosityLevel
source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
Assign values from
ArgMatches to self.source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
Assign values from
ArgMatches to self.source§impl Hash for VerbosityLevel
impl Hash for VerbosityLevel
source§impl Parser for VerbosityLevel
impl Parser for VerbosityLevel
source§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
Parse from iterator, exit on error.
source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
Parse from iterator, return Err on error.
source§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
Update from iterator, exit on error.
source§impl PartialEq for VerbosityLevel
impl PartialEq for VerbosityLevel
source§fn eq(&self, other: &VerbosityLevel) -> bool
fn eq(&self, other: &VerbosityLevel) -> bool
This method tests for
self and other values to be equal, and is used
by ==.impl Eq for VerbosityLevel
impl StructuralPartialEq for VerbosityLevel
Auto Trait Implementations§
impl Freeze for VerbosityLevel
impl RefUnwindSafe for VerbosityLevel
impl Send for VerbosityLevel
impl Sync for VerbosityLevel
impl Unpin for VerbosityLevel
impl UnwindSafe for VerbosityLevel
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.