1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use clap::{Args, Parser};
use tracing::{metadata::LevelFilter, Level};
use crate::search::Search;
/// Tool for listing project directories.
#[derive(Debug, Clone, Default, Parser)]
#[command(author, version, about)]
pub struct Config {
#[command(flatten)]
pub search: Search,
#[command(flatten)]
pub verbosity: Verbosity,
}
#[derive(Debug, Default, Clone, Args)]
pub struct Verbosity {
/// Print additional information per occurrence.
///
/// Conflicts with `--quiet`.
#[arg(short, long, global = true, action = clap::ArgAction::Count, conflicts_with = "quiet")]
pub verbose: u8,
/// Suppress all output.
///
/// Conflicts with `--verbose`.
#[arg(short, long, global = true, conflicts_with = "verbose")]
pub quiet: bool,
}
impl From<&Verbosity> for Option<Level> {
fn from(value: &Verbosity) -> Self {
match 1 + value.verbose - u8::from(value.quiet) {
0 => None,
1 => Some(Level::ERROR),
2 => Some(Level::WARN),
3 => Some(Level::INFO),
4 => Some(Level::DEBUG),
_ => Some(Level::TRACE),
}
}
}
impl From<&Verbosity> for LevelFilter {
fn from(value: &Verbosity) -> Self {
Option::<Level>::from(value).into()
}
}
|