2022-06-18 21:56:31 -07:00
|
|
|
use super::*;
|
2016-10-23 16:43:52 -07:00
|
|
|
|
2024-06-19 20:57:46 -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)]
|
2024-06-19 16:25:36 -07:00
|
|
|
pub fn run(args: impl Iterator<Item = impl Into<OsString> + Clone>) -> Result<(), i32> {
|
2018-05-06 19:02:17 -07:00
|
|
|
#[cfg(windows)]
|
2019-10-09 00:18:53 -07:00
|
|
|
ansi_term::enable_ansi_support().ok();
|
2018-05-06 19:02:17 -07:00
|
|
|
|
2018-08-27 16:03:52 -07:00
|
|
|
env_logger::Builder::from_env(
|
2018-12-08 14:29:41 -08:00
|
|
|
env_logger::Env::new()
|
|
|
|
.filter("JUST_LOG")
|
|
|
|
.write_style("JUST_LOG_STYLE"),
|
|
|
|
)
|
2024-06-19 00:50:37 -07:00
|
|
|
.try_init()
|
|
|
|
.ok();
|
2018-08-27 16:03:52 -07:00
|
|
|
|
2019-10-07 02:06:45 -07:00
|
|
|
let app = Config::app();
|
2019-07-18 21:58:06 -07:00
|
|
|
|
2020-03-31 00:00:05 -07:00
|
|
|
info!("Parsing command line arguments…");
|
2024-06-19 20:57:46 -07:00
|
|
|
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
|
|
|
|
2022-09-11 01:23:28 -07:00
|
|
|
let config = Config::from_matches(&matches).map_err(Error::from);
|
2021-07-26 01:26:06 -07:00
|
|
|
|
2023-11-21 11:28:59 -08:00
|
|
|
let (color, verbosity) = config
|
2022-09-11 01:23:28 -07:00
|
|
|
.as_ref()
|
2023-11-21 11:28:59 -08:00
|
|
|
.map(|config| (config.color, config.verbosity))
|
|
|
|
.unwrap_or((Color::auto(), Verbosity::default()));
|
2023-01-12 19:25:28 -08:00
|
|
|
|
2023-11-21 11:28:59 -08:00
|
|
|
let loader = Loader::new();
|
2022-09-11 01:23:28 -07:00
|
|
|
|
|
|
|
config
|
|
|
|
.and_then(|config| config.run(&loader))
|
2021-07-26 01:26:06 -07:00
|
|
|
.map_err(|error| {
|
2022-10-31 00:52:03 -07:00
|
|
|
if !verbosity.quiet() && error.print_message() {
|
2021-07-28 18:27:47 -07:00
|
|
|
eprintln!("{}", error.color_display(color.stderr()));
|
2021-07-26 01:26:06 -07:00
|
|
|
}
|
|
|
|
error.code().unwrap_or(EXIT_FAILURE)
|
|
|
|
})
|
2016-10-23 16:43:52 -07:00
|
|
|
}
|