From 816183b9750c53e0c5ed2e0c0f37e82773fc1be9 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 31 Aug 2018 00:04:06 -0700 Subject: [PATCH] Add grandiloquent verbosity level that echos shebang recipes (#348) --- src/common.rs | 1 + src/configuration.rs | 4 ++-- src/main.rs | 3 ++- src/recipe.rs | 17 +++++++++++------ src/run.rs | 5 ++++- src/verbosity.rs | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 src/verbosity.rs diff --git a/src/common.rs b/src/common.rs index c08ea9f681..39868632d5 100644 --- a/src/common.rs +++ b/src/common.rs @@ -35,3 +35,4 @@ pub use recipe_resolver::RecipeResolver; pub use runtime_error::{RuntimeError, RunResult}; pub use shebang::Shebang; pub use token::{Token, TokenKind}; +pub use verbosity::Verbosity; diff --git a/src/configuration.rs b/src/configuration.rs index dab2ef6ea0..77d662e2c9 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -10,7 +10,7 @@ pub struct Configuration<'a> { pub quiet: bool, pub shell: &'a str, pub color: Color, - pub verbose: bool, + pub verbosity: Verbosity, } impl<'a> Default for Configuration<'a> { @@ -23,7 +23,7 @@ impl<'a> Default for Configuration<'a> { quiet: false, shell: DEFAULT_SHELL, color: default(), - verbose: false, + verbosity: Verbosity::from_flag_occurrences(0), } } } diff --git a/src/main.rs b/src/main.rs index 43fe460c8d..67f2947fc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,7 @@ mod cooked_string; mod expression; mod fragment; mod function; +mod interrupt_handler; mod justfile; mod lexer; mod load_dotenv; @@ -47,7 +48,7 @@ mod run; mod runtime_error; mod shebang; mod token; -mod interrupt_handler; +mod verbosity; use common::*; diff --git a/src/recipe.rs b/src/recipe.rs index eac3e3ca42..90cea69e34 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -63,7 +63,7 @@ impl<'a> Recipe<'a> { ) -> RunResult<'a, ()> { let configuration = &context.configuration; - if configuration.verbose { + if configuration.verbosity.loquacious() { let color = configuration.color.stderr().banner(); eprintln!("{}===> Running recipe `{}`...{}", color.prefix(), self.name, color.suffix()); } @@ -141,6 +141,11 @@ impl<'a> Recipe<'a> { text += line; text += "\n"; } + + if configuration.verbosity.grandiloquent() { + eprintln!("{}", configuration.color.doc().stderr().paint(&text)); + } + f.write_all(text.as_bytes()) .map_err(|error| RuntimeError::TmpdirIoError{recipe: self.name, io_error: error})?; } @@ -212,11 +217,11 @@ impl<'a> Recipe<'a> { continue; } - if configuration.dry_run || - configuration.verbose || - !((quiet_command ^ self.quiet) || - configuration.quiet - ) { + if configuration.dry_run + || configuration.verbosity.loquacious() + || !((quiet_command ^ self.quiet) + || configuration.quiet) + { let color = if configuration.highlight { configuration.color.command() } else { diff --git a/src/run.rs b/src/run.rs index 9e6e4c355f..baaa91ba09 100644 --- a/src/run.rs +++ b/src/run.rs @@ -121,6 +121,7 @@ pub fn run() { .arg(Arg::with_name("VERBOSE") .short("v") .long("verbose") + .multiple(true) .help("Use verbose output")) .arg(Arg::with_name("WORKING-DIRECTORY") .short("d") @@ -344,13 +345,15 @@ pub fn run() { die!("Justfile contains no recipes."); }; + let verbosity = Verbosity::from_flag_occurrences(matches.occurrences_of("VERBOSE")); + let configuration = Configuration { dry_run: matches.is_present("DRY-RUN"), evaluate: matches.is_present("EVALUATE"), highlight: matches.is_present("HIGHLIGHT"), quiet: matches.is_present("QUIET"), shell: matches.value_of("SHELL").unwrap(), - verbose: matches.is_present("VERBOSE"), + verbosity, color, overrides, }; diff --git a/src/verbosity.rs b/src/verbosity.rs new file mode 100644 index 0000000000..5f2cab76e7 --- /dev/null +++ b/src/verbosity.rs @@ -0,0 +1,34 @@ +use Verbosity::*; + +#[derive(Copy, Clone)] +pub enum Verbosity { + Taciturn, + Loquacious, + Grandiloquent, +} + +impl Verbosity { + pub fn from_flag_occurrences(flag_occurences: u64) -> Verbosity { + match flag_occurences { + 0 => Taciturn, + 1 => Loquacious, + _ => Grandiloquent, + } + } + + pub fn loquacious(self) -> bool { + match self { + Taciturn => false, + Loquacious => true, + Grandiloquent => true, + } + } + + pub fn grandiloquent(self) -> bool { + match self { + Taciturn => false, + Loquacious => false, + Grandiloquent => true, + } + } +}