Skip to content

Commit

Permalink
Add grandiloquent verbosity level that echos shebang recipes (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Aug 31, 2018
1 parent 4e6585d commit 816183b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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),
}
}
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod cooked_string;
mod expression;
mod fragment;
mod function;
mod interrupt_handler;
mod justfile;
mod lexer;
mod load_dotenv;
Expand All @@ -47,7 +48,7 @@ mod run;
mod runtime_error;
mod shebang;
mod token;
mod interrupt_handler;
mod verbosity;

use common::*;

Expand Down
17 changes: 11 additions & 6 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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})?;
}
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
};
Expand Down
34 changes: 34 additions & 0 deletions src/verbosity.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}

0 comments on commit 816183b

Please sign in to comment.