From b3f6ba6edbcceb9dbeed6b32c2df22303093f736 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 25 Sep 2026 14:17:38 -0700 Subject: [PATCH] Use consistent spacing in `--usage` output --- src/usage.rs | 5 +--- tests/usage.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/usage.rs b/src/usage.rs index 881d7d47f5..fb48dc1059 100644 --- a/src/usage.rs +++ b/src/usage.rs @@ -80,10 +80,7 @@ impl ColorDisplay for Usage<'_, D> { } if options { - if arguments { - writeln!(f)?; - } - + writeln!(f)?; writeln!(f)?; writeln!(f, "{}", color.heading().paint("Options:"))?; for (i, parameter) in self diff --git a/tests/usage.rs b/tests/usage.rs index 52cc5d208f..bd6aa07bbd 100644 --- a/tests/usage.rs +++ b/tests/usage.rs @@ -66,6 +66,76 @@ foo a b c='abc' d e f='xyz' g='bar' *h: .success(); } +#[test] +fn no_sections() { + Test::new() + .justfile("foo:") + .args(["--usage", "foo"]) + .stdout("Usage: just foo\n") + .success(); +} + +#[test] +fn arguments_only() { + Test::new() + .justfile("foo bar:") + .args(["--usage", "foo"]) + .stdout( + " + Usage: just foo bar + + Arguments: + bar + ", + ) + .success(); +} + +#[test] +fn options_only() { + Test::new() + .justfile( + " + [arg('bar', short='b')] + foo bar: + ", + ) + .args(["--usage", "foo"]) + .stdout( + " + Usage: just foo [OPTIONS] + + Options: + -b bar + ", + ) + .success(); +} + +#[test] +fn arguments_and_options() { + Test::new() + .justfile( + " + [arg('bar', short='b')] + foo bar baz: + ", + ) + .args(["--usage", "foo"]) + .stdout( + " + Usage: just foo [OPTIONS] baz + + Arguments: + baz + + Options: + -b bar + ", + ) + .success(); +} + #[test] fn flags_have_no_value_placeholder() { Test::new() @@ -82,6 +152,7 @@ fn flags_have_no_value_placeholder() { .stdout( " Usage: just foo [OPTIONS] + Options: --bar a flag ",