Refactor run.rs (#1335)

Remove mutation of the color and verbosity variables and make it
slightly easier to figure out how it works.
This commit is contained in:
Greg Shuflin 2022-09-11 01:23:28 -07:00 committed by GitHub
parent 154930cc8a
commit b4d6000dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()));