Skip to content

Commit

Permalink
List recipes by group in group justfile order with `just --list --uns…
Browse files Browse the repository at this point in the history
…orted` (#2164)
  • Loading branch information
casey authored Jun 15, 2024
1 parent 4a59769 commit 197e100
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
Expand All @@ -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()
Expand Down
41 changes: 41 additions & 0 deletions tests/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 197e100

Please sign in to comment.