From b4d6000dd20e0869f564fbd24f55caa08e4348d1 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 11 Sep 2022 01:23:28 -0700 Subject: [PATCH] Refactor run.rs (#1335) Remove mutation of the color and verbosity variables and make it slightly easier to figure out how it works. --- src/run.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/run.rs b/src/run.rs index 73be1b5..69477cb 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,5 +1,6 @@ use super::*; +/// Main entry point into just binary. pub fn run() -> Result<(), i32> { #[cfg(windows)] ansi_term::enable_ansi_support().ok(); @@ -18,16 +19,15 @@ pub fn run() -> Result<(), i32> { let loader = Loader::new(); - let mut color = Color::auto(); - let mut verbosity = Verbosity::default(); + let config = Config::from_matches(&matches).map_err(Error::from); - Config::from_matches(&matches) - .map_err(Error::from) - .and_then(|config| { - color = config.color; - verbosity = config.verbosity; - config.run(&loader) - }) + let (color, verbosity) = config + .as_ref() + .map(|config| (config.color, config.verbosity)) + .unwrap_or((Color::auto(), Verbosity::default())); + + config + .and_then(|config| config.run(&loader)) .map_err(|error| { if !verbosity.quiet() { eprintln!("{}", error.color_display(color.stderr()));