Skip to content

Commit

Permalink
Print space before submodules in --list with groups (#2244)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jul 14, 2024
1 parent 458805e commit 6747c79
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
6 changes: 4 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ watch +args='test':
test:
cargo test

ci: build-book
ci: lint build-book
cargo test --all

lint:
cargo clippy --all --all-targets -- --deny warnings
cargo fmt --all -- --check
./bin/forbid
cargo fmt --all -- --check
cargo update --locked --package just

fuzz:
Expand Down
10 changes: 7 additions & 3 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ impl Subcommand {
ordered.insert(0, None);
}

let no_groups = groups.contains_key(&None) && groups.len() == 1;

for (i, group) in ordered.into_iter().enumerate() {
if i > 0 {
println!();
}

let no_groups = groups.contains_key(&None) && groups.len() == 1;

if !no_groups {
print!("{list_prefix}");
if let Some(group) = &group {
Expand Down Expand Up @@ -605,7 +605,11 @@ impl Subcommand {
Self::list_module(config, submodule, depth + 1);
}
} else {
for submodule in module.modules(config) {
for (i, submodule) in module.modules(config).into_iter().enumerate() {
if !no_groups && !groups.is_empty() && i == 0 {
println!();
}

print!("{list_prefix}{} ...", submodule.name());
format_doc(
config,
Expand Down
46 changes: 46 additions & 0 deletions tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,49 @@ fn module_doc_aligned() {
)
.run();
}

#[test]
fn space_before_submodules_following_groups() {
Test::new()
.write("foo.just", "")
.justfile(
"
mod foo
[group: 'baz']
bar:
",
)
.test_round_trip(false)
.args(["--unstable", "--list"])
.stdout(
"
Available recipes:
[baz]
bar
foo ...
",
)
.run();
}

#[test]
fn no_space_before_submodules_not_following_groups() {
Test::new()
.write("foo.just", "")
.justfile(
"
mod foo
",
)
.test_round_trip(false)
.args(["--unstable", "--list"])
.stdout(
"
Available recipes:
foo ...
",
)
.run();
}

0 comments on commit 6747c79

Please sign in to comment.