Emit log level separately from Args

This commit is contained in:
Félix Saparelli 2021-04-11 01:09:28 +12:00
parent 757de0d92e
commit 31fd818247
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
2 changed files with 15 additions and 14 deletions

View File

@ -120,12 +120,12 @@ pub fn clear_screen() {
}
#[deprecated(since = "1.15.0", note = "this will be removed from the library API. use the builder")]
pub fn get_args() -> error::Result<Args> {
pub fn get_args() -> error::Result<(Args, LevelFilter)> {
get_args_impl(None::<&[&str]>)
}
#[deprecated(since = "1.15.0", note = "this will be removed from the library API. use the builder")]
pub fn get_args_from<I, T>(from: I) -> error::Result<Args>
pub fn get_args_from<I, T>(from: I) -> error::Result<(Args, LevelFilter)>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
@ -133,7 +133,7 @@ where
get_args_impl(Some(from))
}
fn get_args_impl<I, T>(from: Option<I>) -> error::Result<Args>
fn get_args_impl<I, T>(from: Option<I>) -> error::Result<(Args, LevelFilter)>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
@ -326,5 +326,13 @@ where
config.once = true;
}
Ok(config)
let loglevel = if args.is_present("verbose") {
LevelFilter::Debug
} else if args.is_present("changes") {
LevelFilter::Info
} else {
LevelFilter::Warn
};
Ok((config, loglevel))
}

View File

@ -5,16 +5,9 @@ extern crate watchexec;
use watchexec::{cli, error, run};
fn main() -> error::Result<()> {
let args = cli::get_args()?;
if args.debug {
init_logger(log::LevelFilter::Debug);
} else if args.changes {
init_logger(log::LevelFilter::Info);
} else {
init_logger(log::LevelFilter::Warn);
}
#[allow(deprecated)]
let (args, loglevel) = cli::get_args()?;
init_logger(loglevel);
run(args)
}