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

source

pub fn changed(&self) -> bool

true only if no verbose and no quiet was set (user is using defaults)

source

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}")
        }
    }
}
source

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);
source

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);
source

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);
source

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);
source

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);

Trait Implementations§

source§

impl Args for VerbosityLevel

source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self. Read more
source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can update self. Read more
source§

impl Clone for VerbosityLevel

source§

fn clone(&self) -> VerbosityLevel

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl CommandFactory for VerbosityLevel

source§

fn command<'b>() -> Command

Build a Command that can instantiate Self. Read more
source§

fn command_for_update<'b>() -> Command

Build a Command that can update self. Read more
source§

impl Debug for VerbosityLevel

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for VerbosityLevel

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl FromArgMatches for VerbosityLevel

source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
source§

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>

Assign values from ArgMatches to self.
source§

impl Hash for VerbosityLevel

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Parser for VerbosityLevel

source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error.
source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
source§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error.
source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
source§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error.
source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.
source§

impl PartialEq for VerbosityLevel

source§

fn eq(&self, other: &VerbosityLevel) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for VerbosityLevel

source§

impl StructuralPartialEq for VerbosityLevel

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more