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:
parent
154930cc8a
commit
b4d6000dd2
18
src/run.rs
18
src/run.rs
@ -1,5 +1,6 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
/// Main entry point into just binary.
|
||||||
pub fn run() -> Result<(), i32> {
|
pub fn run() -> Result<(), i32> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
ansi_term::enable_ansi_support().ok();
|
ansi_term::enable_ansi_support().ok();
|
||||||
@ -18,16 +19,15 @@ pub fn run() -> Result<(), i32> {
|
|||||||
|
|
||||||
let loader = Loader::new();
|
let loader = Loader::new();
|
||||||
|
|
||||||
let mut color = Color::auto();
|
let config = Config::from_matches(&matches).map_err(Error::from);
|
||||||
let mut verbosity = Verbosity::default();
|
|
||||||
|
|
||||||
Config::from_matches(&matches)
|
let (color, verbosity) = config
|
||||||
.map_err(Error::from)
|
.as_ref()
|
||||||
.and_then(|config| {
|
.map(|config| (config.color, config.verbosity))
|
||||||
color = config.color;
|
.unwrap_or((Color::auto(), Verbosity::default()));
|
||||||
verbosity = config.verbosity;
|
|
||||||
config.run(&loader)
|
config
|
||||||
})
|
.and_then(|config| config.run(&loader))
|
||||||
.map_err(|error| {
|
.map_err(|error| {
|
||||||
if !verbosity.quiet() {
|
if !verbosity.quiet() {
|
||||||
eprintln!("{}", error.color_display(color.stderr()));
|
eprintln!("{}", error.color_display(color.stderr()));
|
||||||
|
Loading…
Reference in New Issue
Block a user