mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Add very verbose output flag
This commit is contained in:
parent
f6d6c9435c
commit
474e9f5e31
2 changed files with 16 additions and 8 deletions
|
|
@ -92,6 +92,7 @@ impl CliProgress {
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub struct CliLogger {
|
pub struct CliLogger {
|
||||||
|
all: bool,
|
||||||
level: LevelFilter,
|
level: LevelFilter,
|
||||||
progress: Mutex<Option<CliProgress>>,
|
progress: Mutex<Option<CliProgress>>,
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +106,7 @@ impl Log for CliLogger {
|
||||||
if !self.enabled(record.metadata())
|
if !self.enabled(record.metadata())
|
||||||
|| (record.target() != "progress"
|
|| (record.target() != "progress"
|
||||||
&& record.target() != "progress_end"
|
&& record.target() != "progress_end"
|
||||||
&& !record.target().starts_with("crunchy_cli"))
|
&& (!self.all && !record.target().starts_with("crunchy_cli")))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -136,16 +137,17 @@ impl Log for CliLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliLogger {
|
impl CliLogger {
|
||||||
pub fn new(level: LevelFilter) -> Self {
|
pub fn new(all: bool, level: LevelFilter) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
all,
|
||||||
level,
|
level,
|
||||||
progress: Mutex::new(None),
|
progress: Mutex::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(level: LevelFilter) -> Result<(), SetLoggerError> {
|
pub fn init(all: bool, level: LevelFilter) -> Result<(), SetLoggerError> {
|
||||||
set_max_level(level);
|
set_max_level(level);
|
||||||
set_boxed_logger(Box::new(CliLogger::new(level)))
|
set_boxed_logger(Box::new(CliLogger::new(all, level)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extended(&self, record: &Record) {
|
fn extended(&self, record: &Record) {
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ struct Verbosity {
|
||||||
#[arg(short)]
|
#[arg(short)]
|
||||||
v: bool,
|
v: bool,
|
||||||
|
|
||||||
|
#[arg(help = "Very verbose output. Generally not recommended, use '-v' instead")]
|
||||||
|
#[arg(long)]
|
||||||
|
vv: bool,
|
||||||
|
|
||||||
#[arg(help = "Quiet output. Does not print anything unless it's a error")]
|
#[arg(help = "Quiet output. Does not print anything unless it's a error")]
|
||||||
#[arg(
|
#[arg(
|
||||||
long_help = "Quiet output. Does not print anything unless it's a error. Can be helpful if you pipe the output to stdout"
|
long_help = "Quiet output. Does not print anything unless it's a error. Can be helpful if you pipe the output to stdout"
|
||||||
|
|
@ -92,16 +96,18 @@ pub async fn cli_entrypoint() {
|
||||||
let cli: Cli = Cli::parse();
|
let cli: Cli = Cli::parse();
|
||||||
|
|
||||||
if let Some(verbosity) = &cli.verbosity {
|
if let Some(verbosity) = &cli.verbosity {
|
||||||
if verbosity.v && verbosity.q {
|
if verbosity.v as u8 + verbosity.q as u8 + verbosity.vv as u8 > 1 {
|
||||||
eprintln!("Output cannot be verbose ('-v') and quiet ('-q') at the same time");
|
eprintln!("Output cannot be verbose ('-v') and quiet ('-q') at the same time");
|
||||||
std::process::exit(1)
|
std::process::exit(1)
|
||||||
} else if verbosity.v {
|
} else if verbosity.v {
|
||||||
CliLogger::init(LevelFilter::Debug).unwrap()
|
CliLogger::init(false, LevelFilter::Debug).unwrap()
|
||||||
} else if verbosity.q {
|
} else if verbosity.q {
|
||||||
CliLogger::init(LevelFilter::Error).unwrap()
|
CliLogger::init(false, LevelFilter::Error).unwrap()
|
||||||
|
} else if verbosity.vv {
|
||||||
|
CliLogger::init(true, LevelFilter::Debug).unwrap()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CliLogger::init(LevelFilter::Info).unwrap()
|
CliLogger::init(false, LevelFilter::Info).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("cli input: {:?}", cli);
|
debug!("cli input: {:?}", cli);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue