diff --git a/src/assignment_evaluator.rs b/src/assignment_evaluator.rs index fbde502..333ecd4 100644 --- a/src/assignment_evaluator.rs +++ b/src/assignment_evaluator.rs @@ -167,12 +167,12 @@ b = `echo $exported_variable` recipe: echo {{b}} "#; - let options = Configuration { + let configuration = Configuration { quiet: true, ..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(_)} => { assert_eq!(token.lexeme, "`echo $exported_variable`"); }, diff --git a/src/justfile.rs b/src/justfile.rs index 0122461..7bfd889 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -44,10 +44,10 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b { pub fn run( &'a self, - arguments: &[&'a str], - options: &Configuration<'a>, + arguments: &[&'a str], + configuration: &Configuration<'a>, ) -> RunResult<'a, ()> { - let unknown_overrides = options.overrides.keys().cloned() + let unknown_overrides = configuration.overrides.keys().cloned() .filter(|name| !self.assignments.contains_key(name)) .collect::>(); @@ -57,13 +57,13 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b { let scope = evaluate_assignments( &self.assignments, - &options.overrides, - options.quiet, - options.shell, - options.dry_run, + &configuration.overrides, + configuration.quiet, + configuration.shell, + configuration.dry_run, )?; - if options.evaluate { + if configuration.evaluate { let mut width = 0; for name in scope.keys() { width = cmp::max(name.len(), width); @@ -114,7 +114,7 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b { let mut ran = empty(); for (recipe, arguments) in grouped { - self.run_recipe(recipe, arguments, &scope, &mut ran, options)? + self.run_recipe(recipe, arguments, &scope, &mut ran, configuration)? } Ok(()) @@ -122,18 +122,18 @@ impl<'a, 'b> Justfile<'a> where 'a: 'b { fn run_recipe<'c>( &'c self, - recipe: &Recipe<'a>, - arguments: &[&'a str], - scope: &Map<&'c str, String>, - ran: &mut Set<&'a str>, - options: &Configuration<'a>, + recipe: &Recipe<'a>, + arguments: &[&'a str], + scope: &Map<&'c str, String>, + ran: &mut Set<&'a str>, + configuration: &Configuration<'a>, ) -> RunResult<()> { for dependency_name in &recipe.dependencies { 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); Ok(()) } @@ -305,11 +305,11 @@ a return code: #[test] fn unknown_overrides() { - let mut options: Configuration = Default::default(); - options.overrides.insert("foo", "bar"); - options.overrides.insert("baz", "bob"); + let mut configuration: Configuration = Default::default(); + configuration.overrides.insert("foo", "bar"); + configuration.overrides.insert("baz", "bob"); match parse_success("a:\n echo {{`f() { return 100; }; f`}}") - .run(&["a"], &options).unwrap_err() { + .run(&["a"], &configuration).unwrap_err() { RuntimeError::UnknownOverrides{overrides} => { assert_eq!(overrides, &["baz", "foo"]); }, @@ -329,12 +329,12 @@ wut: echo $foo $bar $baz "#; - let options = Configuration { + let configuration = Configuration { quiet: true, ..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} => { assert_eq!(recipe, "wut"); assert_eq!(line_number, Some(8)); diff --git a/src/recipe.rs b/src/recipe.rs index bece0ad..ab8e9f3 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -50,13 +50,13 @@ impl<'a> Recipe<'a> { pub fn run( &self, - arguments: &[&'a str], - scope: &Map<&'a str, String>, - exports: &Set<&'a str>, - options: &Configuration, + arguments: &[&'a str], + scope: &Map<&'a str, String>, + exports: &Set<&'a str>, + configuration: &Configuration, ) -> RunResult<'a, ()> { - if options.verbose { - let color = options.color.stderr().banner(); + if configuration.verbose { + let color = configuration.color.stderr().banner(); eprintln!("{}===> Running recipe `{}`...{}", color.prefix(), self.name, color.suffix()); } @@ -89,9 +89,9 @@ impl<'a> Recipe<'a> { exports: exports, assignments: &empty(), overrides: &empty(), - quiet: options.quiet, - shell: options.shell, - dry_run: options.dry_run, + quiet: configuration.quiet, + shell: configuration.shell, + dry_run: configuration.dry_run, }; if self.shebang { @@ -100,13 +100,13 @@ impl<'a> Recipe<'a> { 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 { eprintln!("{}", line); } } - if options.dry_run { + if configuration.dry_run { return Ok(()); } @@ -202,24 +202,28 @@ impl<'a> Recipe<'a> { continue; } - if options.dry_run || options.verbose || !((quiet_command ^ self.quiet) || options.quiet) { - let color = if options.highlight { - options.color.command() + if configuration.dry_run || + configuration.verbose || + !((quiet_command ^ self.quiet) || + configuration.quiet + ) { + let color = if configuration.highlight { + configuration.color.command() } else { - options.color + configuration.color }; eprintln!("{}", color.stderr().paint(command)); } - if options.dry_run { + if configuration.dry_run { continue; } - let mut cmd = Command::new(options.shell); + let mut cmd = Command::new(configuration.shell); cmd.arg("-cu").arg(command); - if options.quiet { + if configuration.quiet { cmd.stderr(Stdio::null()); cmd.stdout(Stdio::null()); } diff --git a/src/run.rs b/src/run.rs index e11cc1b..2b5cb89 100644 --- a/src/run.rs +++ b/src/run.rs @@ -310,7 +310,7 @@ pub fn run() { die!("Justfile contains no recipes."); }; - let options = Configuration { + let configuration = Configuration { dry_run: matches.is_present("DRY-RUN"), evaluate: matches.is_present("EVALUATE"), highlight: matches.is_present("HIGHLIGHT"), @@ -321,8 +321,8 @@ pub fn run() { verbose: matches.is_present("VERBOSE"), }; - if let Err(run_error) = justfile.run(&arguments, &options) { - if !options.quiet { + if let Err(run_error) = justfile.run(&arguments, &configuration) { + if !configuration.quiet { if color.stderr().active() { eprintln!("{:#}", run_error); } else {