Add grandiloquent verbosity level that echos shebang recipes (#348)
This commit is contained in:
parent
4e6585d391
commit
816183b975
@ -35,3 +35,4 @@ pub use recipe_resolver::RecipeResolver;
|
|||||||
pub use runtime_error::{RuntimeError, RunResult};
|
pub use runtime_error::{RuntimeError, RunResult};
|
||||||
pub use shebang::Shebang;
|
pub use shebang::Shebang;
|
||||||
pub use token::{Token, TokenKind};
|
pub use token::{Token, TokenKind};
|
||||||
|
pub use verbosity::Verbosity;
|
||||||
|
@ -10,7 +10,7 @@ pub struct Configuration<'a> {
|
|||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
pub shell: &'a str,
|
pub shell: &'a str,
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
pub verbose: bool,
|
pub verbosity: Verbosity,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for Configuration<'a> {
|
impl<'a> Default for Configuration<'a> {
|
||||||
@ -23,7 +23,7 @@ impl<'a> Default for Configuration<'a> {
|
|||||||
quiet: false,
|
quiet: false,
|
||||||
shell: DEFAULT_SHELL,
|
shell: DEFAULT_SHELL,
|
||||||
color: default(),
|
color: default(),
|
||||||
verbose: false,
|
verbosity: Verbosity::from_flag_occurrences(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ mod cooked_string;
|
|||||||
mod expression;
|
mod expression;
|
||||||
mod fragment;
|
mod fragment;
|
||||||
mod function;
|
mod function;
|
||||||
|
mod interrupt_handler;
|
||||||
mod justfile;
|
mod justfile;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
mod load_dotenv;
|
mod load_dotenv;
|
||||||
@ -47,7 +48,7 @@ mod run;
|
|||||||
mod runtime_error;
|
mod runtime_error;
|
||||||
mod shebang;
|
mod shebang;
|
||||||
mod token;
|
mod token;
|
||||||
mod interrupt_handler;
|
mod verbosity;
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ impl<'a> Recipe<'a> {
|
|||||||
) -> RunResult<'a, ()> {
|
) -> RunResult<'a, ()> {
|
||||||
let configuration = &context.configuration;
|
let configuration = &context.configuration;
|
||||||
|
|
||||||
if configuration.verbose {
|
if configuration.verbosity.loquacious() {
|
||||||
let color = configuration.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());
|
||||||
}
|
}
|
||||||
@ -141,6 +141,11 @@ impl<'a> Recipe<'a> {
|
|||||||
text += line;
|
text += line;
|
||||||
text += "\n";
|
text += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if configuration.verbosity.grandiloquent() {
|
||||||
|
eprintln!("{}", configuration.color.doc().stderr().paint(&text));
|
||||||
|
}
|
||||||
|
|
||||||
f.write_all(text.as_bytes())
|
f.write_all(text.as_bytes())
|
||||||
.map_err(|error| RuntimeError::TmpdirIoError{recipe: self.name, io_error: error})?;
|
.map_err(|error| RuntimeError::TmpdirIoError{recipe: self.name, io_error: error})?;
|
||||||
}
|
}
|
||||||
@ -212,11 +217,11 @@ impl<'a> Recipe<'a> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if configuration.dry_run ||
|
if configuration.dry_run
|
||||||
configuration.verbose ||
|
|| configuration.verbosity.loquacious()
|
||||||
!((quiet_command ^ self.quiet) ||
|
|| !((quiet_command ^ self.quiet)
|
||||||
configuration.quiet
|
|| configuration.quiet)
|
||||||
) {
|
{
|
||||||
let color = if configuration.highlight {
|
let color = if configuration.highlight {
|
||||||
configuration.color.command()
|
configuration.color.command()
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,6 +121,7 @@ pub fn run() {
|
|||||||
.arg(Arg::with_name("VERBOSE")
|
.arg(Arg::with_name("VERBOSE")
|
||||||
.short("v")
|
.short("v")
|
||||||
.long("verbose")
|
.long("verbose")
|
||||||
|
.multiple(true)
|
||||||
.help("Use verbose output"))
|
.help("Use verbose output"))
|
||||||
.arg(Arg::with_name("WORKING-DIRECTORY")
|
.arg(Arg::with_name("WORKING-DIRECTORY")
|
||||||
.short("d")
|
.short("d")
|
||||||
@ -344,13 +345,15 @@ pub fn run() {
|
|||||||
die!("Justfile contains no recipes.");
|
die!("Justfile contains no recipes.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let verbosity = Verbosity::from_flag_occurrences(matches.occurrences_of("VERBOSE"));
|
||||||
|
|
||||||
let configuration = 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"),
|
||||||
quiet: matches.is_present("QUIET"),
|
quiet: matches.is_present("QUIET"),
|
||||||
shell: matches.value_of("SHELL").unwrap(),
|
shell: matches.value_of("SHELL").unwrap(),
|
||||||
verbose: matches.is_present("VERBOSE"),
|
verbosity,
|
||||||
color,
|
color,
|
||||||
overrides,
|
overrides,
|
||||||
};
|
};
|
||||||
|
34
src/verbosity.rs
Normal file
34
src/verbosity.rs
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user