Rename options to configuration (#254)

This commit is contained in:
Casey Rodarmor 2017-11-17 23:23:02 -08:00 committed by GitHub
parent acb5d6f98b
commit 7166fa9e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 45 deletions

View File

@ -167,12 +167,12 @@ b = `echo $exported_variable`
recipe: recipe:
echo {{b}} echo {{b}}
"#; "#;
let options = Configuration { let configuration = Configuration {
quiet: true, quiet: true,
..Default::default() ..Default::default()
}; };
match parse_success(text).run(&["recipe"], &options).unwrap_err() { match parse_success(text).run(&["recipe"], &configuration).unwrap_err() {
RuntimeError::Backtick{token, output_error: OutputError::Code(_)} => { RuntimeError::Backtick{token, output_error: OutputError::Code(_)} => {
assert_eq!(token.lexeme, "`echo $exported_variable`"); assert_eq!(token.lexeme, "`echo $exported_variable`");
}, },

View File

@ -45,9 +45,9 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
pub fn run( pub fn run(
&'a self, &'a self,
arguments: &[&'a str], arguments: &[&'a str],
options: &Configuration<'a>, configuration: &Configuration<'a>,
) -> RunResult<'a, ()> { ) -> RunResult<'a, ()> {
let unknown_overrides = options.overrides.keys().cloned() let unknown_overrides = configuration.overrides.keys().cloned()
.filter(|name| !self.assignments.contains_key(name)) .filter(|name| !self.assignments.contains_key(name))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -57,13 +57,13 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
let scope = evaluate_assignments( let scope = evaluate_assignments(
&self.assignments, &self.assignments,
&options.overrides, &configuration.overrides,
options.quiet, configuration.quiet,
options.shell, configuration.shell,
options.dry_run, configuration.dry_run,
)?; )?;
if options.evaluate { if configuration.evaluate {
let mut width = 0; let mut width = 0;
for name in scope.keys() { for name in scope.keys() {
width = cmp::max(name.len(), width); width = cmp::max(name.len(), width);
@ -114,7 +114,7 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
let mut ran = empty(); let mut ran = empty();
for (recipe, arguments) in grouped { for (recipe, arguments) in grouped {
self.run_recipe(recipe, arguments, &scope, &mut ran, options)? self.run_recipe(recipe, arguments, &scope, &mut ran, configuration)?
} }
Ok(()) Ok(())
@ -126,14 +126,14 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b {
arguments: &[&'a str], arguments: &[&'a str],
scope: &Map<&'c str, String>, scope: &Map<&'c str, String>,
ran: &mut Set<&'a str>, ran: &mut Set<&'a str>,
options: &Configuration<'a>, configuration: &Configuration<'a>,
) -> RunResult<()> { ) -> RunResult<()> {
for dependency_name in &recipe.dependencies { for dependency_name in &recipe.dependencies {
if !ran.contains(dependency_name) { if !ran.contains(dependency_name) {
self.run_recipe(&self.recipes[dependency_name], &[], scope, ran, options)?; self.run_recipe(&self.recipes[dependency_name], &[], scope, ran, configuration)?;
} }
} }
recipe.run(arguments, scope, &self.exports, options)?; recipe.run(arguments, scope, &self.exports, configuration)?;
ran.insert(recipe.name); ran.insert(recipe.name);
Ok(()) Ok(())
} }
@ -305,11 +305,11 @@ a return code:
#[test] #[test]
fn unknown_overrides() { fn unknown_overrides() {
let mut options: Configuration = Default::default(); let mut configuration: Configuration = Default::default();
options.overrides.insert("foo", "bar"); configuration.overrides.insert("foo", "bar");
options.overrides.insert("baz", "bob"); configuration.overrides.insert("baz", "bob");
match parse_success("a:\n echo {{`f() { return 100; }; f`}}") match parse_success("a:\n echo {{`f() { return 100; }; f`}}")
.run(&["a"], &options).unwrap_err() { .run(&["a"], &configuration).unwrap_err() {
RuntimeError::UnknownOverrides{overrides} => { RuntimeError::UnknownOverrides{overrides} => {
assert_eq!(overrides, &["baz", "foo"]); assert_eq!(overrides, &["baz", "foo"]);
}, },
@ -329,12 +329,12 @@ wut:
echo $foo $bar $baz echo $foo $bar $baz
"#; "#;
let options = Configuration { let configuration = Configuration {
quiet: true, quiet: true,
..Default::default() ..Default::default()
}; };
match parse_success(text).run(&["wut"], &options).unwrap_err() { match parse_success(text).run(&["wut"], &configuration).unwrap_err() {
RuntimeError::Code{code: _, line_number, recipe} => { RuntimeError::Code{code: _, line_number, recipe} => {
assert_eq!(recipe, "wut"); assert_eq!(recipe, "wut");
assert_eq!(line_number, Some(8)); assert_eq!(line_number, Some(8));

View File

@ -53,10 +53,10 @@ impl<'a> Recipe<'a> {
arguments: &[&'a str], arguments: &[&'a str],
scope: &Map<&'a str, String>, scope: &Map<&'a str, String>,
exports: &Set<&'a str>, exports: &Set<&'a str>,
options: &Configuration, configuration: &Configuration,
) -> RunResult<'a, ()> { ) -> RunResult<'a, ()> {
if options.verbose { if configuration.verbose {
let color = options.color.stderr().banner(); let color = configuration.color.stderr().banner();
eprintln!("{}===> Running recipe `{}`...{}", color.prefix(), self.name, color.suffix()); eprintln!("{}===> Running recipe `{}`...{}", color.prefix(), self.name, color.suffix());
} }
@ -89,9 +89,9 @@ impl<'a> Recipe<'a> {
exports: exports, exports: exports,
assignments: &empty(), assignments: &empty(),
overrides: &empty(), overrides: &empty(),
quiet: options.quiet, quiet: configuration.quiet,
shell: options.shell, shell: configuration.shell,
dry_run: options.dry_run, dry_run: configuration.dry_run,
}; };
if self.shebang { if self.shebang {
@ -100,13 +100,13 @@ impl<'a> Recipe<'a> {
evaluated_lines.push(evaluator.evaluate_line(line, &argument_map)?); evaluated_lines.push(evaluator.evaluate_line(line, &argument_map)?);
} }
if options.dry_run || self.quiet { if configuration.dry_run || self.quiet {
for line in &evaluated_lines { for line in &evaluated_lines {
eprintln!("{}", line); eprintln!("{}", line);
} }
} }
if options.dry_run { if configuration.dry_run {
return Ok(()); return Ok(());
} }
@ -202,24 +202,28 @@ impl<'a> Recipe<'a> {
continue; continue;
} }
if options.dry_run || options.verbose || !((quiet_command ^ self.quiet) || options.quiet) { if configuration.dry_run ||
let color = if options.highlight { configuration.verbose ||
options.color.command() !((quiet_command ^ self.quiet) ||
configuration.quiet
) {
let color = if configuration.highlight {
configuration.color.command()
} else { } else {
options.color configuration.color
}; };
eprintln!("{}", color.stderr().paint(command)); eprintln!("{}", color.stderr().paint(command));
} }
if options.dry_run { if configuration.dry_run {
continue; continue;
} }
let mut cmd = Command::new(options.shell); let mut cmd = Command::new(configuration.shell);
cmd.arg("-cu").arg(command); cmd.arg("-cu").arg(command);
if options.quiet { if configuration.quiet {
cmd.stderr(Stdio::null()); cmd.stderr(Stdio::null());
cmd.stdout(Stdio::null()); cmd.stdout(Stdio::null());
} }

View File

@ -310,7 +310,7 @@ pub fn run() {
die!("Justfile contains no recipes."); die!("Justfile contains no recipes.");
}; };
let options = Configuration { let configuration = Configuration {
dry_run: matches.is_present("DRY-RUN"), dry_run: matches.is_present("DRY-RUN"),
evaluate: matches.is_present("EVALUATE"), evaluate: matches.is_present("EVALUATE"),
highlight: matches.is_present("HIGHLIGHT"), highlight: matches.is_present("HIGHLIGHT"),
@ -321,8 +321,8 @@ pub fn run() {
verbose: matches.is_present("VERBOSE"), verbose: matches.is_present("VERBOSE"),
}; };
if let Err(run_error) = justfile.run(&arguments, &options) { if let Err(run_error) = justfile.run(&arguments, &configuration) {
if !options.quiet { if !configuration.quiet {
if color.stderr().active() { if color.stderr().active() {
eprintln!("{:#}", run_error); eprintln!("{:#}", run_error);
} else { } else {