Fix colors (#927)
- Re-enable error colors - Color argument count mismatch usage string
This commit is contained in:
parent
27cf2b96df
commit
7efb82f4cb
27
src/error.rs
27
src/error.rs
@ -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()))?;
|
||||
|
@ -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)
|
||||
})
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user