From 31fd81824722c965d63fb4cd1b3bc8670c4e323c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sun, 11 Apr 2021 01:09:28 +1200 Subject: [PATCH] Emit log level separately from Args --- src/cli.rs | 16 ++++++++++++---- src/main.rs | 13 +++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 06df10c..3d09eb5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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 { +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(from: I) -> error::Result +pub fn get_args_from(from: I) -> error::Result<(Args, LevelFilter)> where I: IntoIterator, T: Into + Clone, @@ -133,7 +133,7 @@ where get_args_impl(Some(from)) } -fn get_args_impl(from: Option) -> error::Result +fn get_args_impl(from: Option) -> error::Result<(Args, LevelFilter)> where I: IntoIterator, T: Into + 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)) } diff --git a/src/main.rs b/src/main.rs index 504e94a..4c7c15d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) }