Fix colors (#927)

- Re-enable error colors
- Color argument count mismatch usage string
This commit is contained in:
Casey Rodarmor 2021-07-28 18:27:47 -07:00 committed by GitHub
parent 27cf2b96df
commit 7efb82f4cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 9 deletions

View File

@ -200,11 +200,11 @@ impl<'src> ColorDisplay for Error<'src> {
match self {
ArgumentCountMismatch {
recipe,
parameters,
found,
min,
max,
} => {
..
} =>
if min == max {
let expected = min;
write!(
@ -234,12 +234,7 @@ impl<'src> ColorDisplay for Error<'src> {
Count("argument", *found),
max
)?;
}
write!(f, "\nusage:\n just {}", recipe)?;
for param in parameters {
write!(f, " {}", param.color_display(color))?;
}
},
},
Backtick { output_error, .. } => match output_error {
OutputError::Code(code) => {
write!(f, "Backtick failed with exit code {}", code)?;
@ -604,6 +599,22 @@ impl<'src> ColorDisplay for Error<'src> {
write!(f, "{}", color.message().suffix())?;
if let ArgumentCountMismatch {
recipe, parameters, ..
} = self
{
writeln!(f)?;
write!(
f,
"{}:\n just {}",
color.message().paint("usage"),
recipe
)?;
for param in parameters {
write!(f, " {}", param.color_display(color))?;
}
}
if let Some(token) = self.context() {
writeln!(f)?;
write!(f, "{}", token.color_display(color.error()))?;

View File

@ -30,7 +30,7 @@ pub fn run() -> Result<(), i32> {
})
.map_err(|error| {
if !verbosity.quiet() {
eprintln!("{}", error.color_display(color));
eprintln!("{}", error.color_display(color.stderr()));
}
error.code().unwrap_or(EXIT_FAILURE)
})

View File

@ -23,3 +23,19 @@ test! {
",
status: EXIT_FAILURE,
}
#[test]
fn argument_count_mismatch() {
Test::new()
.justfile("foo a b:")
.args(&["foo"])
.stderr(
"
error: Recipe `foo` got 0 arguments but takes 2
usage:
just foo a b
",
)
.status(EXIT_FAILURE)
.run();
}