Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ impl<D> 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
Expand Down
71 changes: 71 additions & 0 deletions tests/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -82,6 +152,7 @@ fn flags_have_no_value_placeholder() {
.stdout(
"
Usage: just foo [OPTIONS]

Options:
--bar a flag
",
Expand Down
Loading