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 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 { if i > 0 {
println!(); println!();
} }
@ -509,14 +519,14 @@ impl Subcommand {
if !no_groups { if !no_groups {
print!("{list_prefix}"); print!("{list_prefix}");
if let Some(group_name) = group { if let Some(group) = &group {
println!("[{group_name}]"); println!("[{group}]");
} else { } else {
println!("(no group)"); println!("(no group)");
} }
} }
for recipe in recipes { for recipe in groups.get(&group).unwrap() {
for (i, name) in iter::once(&recipe.name()) for (i, name) in iter::once(&recipe.name())
.chain(aliases.get(recipe.name()).unwrap_or(&Vec::new())) .chain(aliases.get(recipe.name()).unwrap_or(&Vec::new()))
.enumerate() .enumerate()

View File

@ -96,6 +96,47 @@ fn list_with_groups_unsorted() {
.run(); .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] #[test]
fn list_groups() { fn list_groups() {
Test::new() Test::new()