diff --git a/src/error.rs b/src/error.rs index 377b190..a60b803 100644 --- a/src/error.rs +++ b/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()))?; diff --git a/src/run.rs b/src/run.rs index 4bf8c04..5a0f923 100644 --- a/src/run.rs +++ b/src/run.rs @@ -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) }) diff --git a/tests/error_messages.rs b/tests/error_messages.rs index e4b2e1d..108d376 100644 --- a/tests/error_messages.rs +++ b/tests/error_messages.rs @@ -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(); +}