just/src/run.rs

43 lines
1.1 KiB
Rust
Raw Normal View History

use super::*;
2016-10-23 16:43:52 -07:00
/// Main entry point into `just`. Parse arguments from `args` and run.
2023-06-12 09:53:55 -07:00
#[allow(clippy::missing_errors_doc)]
pub fn run(args: impl Iterator<Item = impl Into<OsString> + Clone>) -> Result<(), i32> {
#[cfg(windows)]
ansi_term::enable_ansi_support().ok();
env_logger::Builder::from_env(
env_logger::Env::new()
.filter("JUST_LOG")
.write_style("JUST_LOG_STYLE"),
)
.try_init()
.ok();
let app = Config::app();
info!("Parsing command line arguments…");
let matches = app.try_get_matches_from(args).map_err(|err| {
err.print().ok();
err.exit_code()
})?;
2016-10-23 16:43:52 -07:00
let config = Config::from_matches(&matches).map_err(Error::from);
let (color, verbosity) = config
.as_ref()
.map(|config| (config.color, config.verbosity))
.unwrap_or((Color::auto(), Verbosity::default()));
2023-01-12 19:25:28 -08:00
let loader = Loader::new();
config
.and_then(|config| config.run(&loader))
.map_err(|error| {
if !verbosity.quiet() && error.print_message() {
eprintln!("{}", error.color_display(color.stderr()));
}
error.code().unwrap_or(EXIT_FAILURE)
})
2016-10-23 16:43:52 -07:00
}