List recipes by group in group justfile order with just --list --unsorted (#2164)

This commit is contained in:
Casey Rodarmor 2024-06-14 20:04:47 -07:00 committed by GitHub
parent 4a59769faa
commit 197e1002d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 4 deletions

View File

@ -500,7 +500,17 @@ impl Subcommand {
groups
};
for (i, (group, recipes)) in groups.iter().enumerate() {
let mut ordered = module
.public_groups(config)
.into_iter()
.map(Some)
.collect::<Vec<Option<String>>>();
if groups.contains_key(&None) {
ordered.insert(0, None);
}
for (i, group) in ordered.into_iter().enumerate() {
if i > 0 {
println!();
}
@ -509,14 +519,14 @@ impl Subcommand {
if !no_groups {
print!("{list_prefix}");
if let Some(group_name) = group {
println!("[{group_name}]");
if let Some(group) = &group {
println!("[{group}]");
} else {
println!("(no group)");
}
}
for recipe in recipes {
for recipe in groups.get(&group).unwrap() {
for (i, name) in iter::once(&recipe.name())
.chain(aliases.get(recipe.name()).unwrap_or(&Vec::new()))
.enumerate()

View File

@ -96,6 +96,47 @@ fn list_with_groups_unsorted() {
.run();
}
#[test]
fn list_with_groups_unsorted_group_order() {
Test::new()
.justfile(
"
[group('y')]
[group('x')]
f:
[group('b')]
b:
[group('a')]
e:
c:
",
)
.args(["--list", "--unsorted"])
.stdout(
"
Available recipes:
(no group)
c
[x]
f
[y]
f
[b]
b
[a]
e
",
)
.run();
}
#[test]
fn list_groups() {
Test::new()