Add grandiloquent verbosity level that echos shebang recipes (#348)

This commit is contained in:
Casey Rodarmor 2018-08-31 00:04:06 -07:00 committed by GitHub
parent 4e6585d391
commit 816183b975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 10 deletions

View File

@ -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;

View File

@ -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),
}
}
}

View File

@ -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::*;

View File

@ -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 {

View File

@ -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,
};

34
src/verbosity.rs Normal file
View File

@ -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,
}
}
}