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_cli::args::VerbosityLevel;
use libpt_log::Level;
use clap::Parser;
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 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);
Sourcepub const WARN: Self
pub const WARN: Self
§Examples
use libpt_log::Level; // reexport: tracing
use libpt_cli::args::VerbosityLevel;
let verbosity_level = VerbosityLevel::WARN;
assert_eq!(verbosity_level.level(), Level::WARN);
Sourcepub const ERROR: Self
pub const ERROR: Self
§Examples
use libpt_log::Level; // reexport: tracing
use libpt_cli::args::VerbosityLevel;
let verbosity_level = VerbosityLevel::ERROR;
assert_eq!(verbosity_level.level(), Level::ERROR);
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 26)
24fn main() {
25 let cli = Cli::parse();
26 let _logger = Logger::builder().set_level(cli.verbosity.level()).build();
27
28 debug!("logger initialized with level: {}", cli.verbosity.level());
29
30 if !cli.machine {
31 let text = cli.text.join(" ");
32 printing::blockprint(text, console::Color::Green);
33 } else {
34 for text in cli.text {
35 println!("{text}")
36 }
37 }
38}
Sourcepub fn level_for_log_crate(&self) -> Level
pub fn level_for_log_crate(&self) -> Level
get the log::Level
for that VerbosityLevel
This is the method for the log crate, which I use less often.
None means that absolutely no output is wanted (completely quiet)
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§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Append to
Command
so it can instantiate self
via
FromArgMatches::update_from_arg_matches_mut
Read moreSource§impl Clone for VerbosityLevel
impl Clone for VerbosityLevel
Source§fn clone(&self) -> VerbosityLevel
fn clone(&self) -> VerbosityLevel
Returns a duplicate 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<'de> Deserialize<'de> for VerbosityLevel
impl<'de> Deserialize<'de> for VerbosityLevel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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)
Source§impl PartialEq for VerbosityLevel
impl PartialEq for VerbosityLevel
Source§impl Serialize for VerbosityLevel
impl Serialize for VerbosityLevel
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