-
Notifications
You must be signed in to change notification settings - Fork 692
Expand file tree
/
Copy pathrun.rs
More file actions
50 lines (41 loc) · 1.33 KB
/
run.rs
File metadata and controls
50 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use super::*;
/// Main entry point into `just`. Parse arguments from `args` and run.
#[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();
let app = Config::app();
let matches = app.try_get_matches_from(args).map_err(|err| {
err.print().ok();
err.exit_code()
})?;
let config = Config::from_matches(&matches).map_err(Error::from);
let (color, verbosity) = config
.as_ref()
.map(|config| (config.color, config.verbosity))
.unwrap_or_default();
let loader = Loader::new();
config
.and_then(|config| {
SignalHandler::install(config.verbosity)?;
config.subcommand.execute(&config, &loader)
})
.map_err(|error| {
if !verbosity.quiet() && error.print_message() {
eprintln!("{}", error.color_display(color.stderr()));
}
error.code().unwrap_or(EXIT_FAILURE)
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn run_can_be_called_more_than_once() {
let tmp = testing::tempdir();
fs::write(tmp.path().join("justfile"), "foo:").unwrap();
let search_directory = format!("{}/", tmp.path().to_str().unwrap());
run(["just", &search_directory].iter()).unwrap();
run(["just", &search_directory].iter()).unwrap();
}
}