From 197e1002d035f60f767f2355e7f857dac86b9da2 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 20:04:47 -0700 Subject: [PATCH] List recipes by group in group justfile order with `just --list --unsorted` (#2164) --- src/subcommand.rs | 18 ++++++++++++++---- tests/groups.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 9b9a246..c001daa 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -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::>>(); + + 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() diff --git a/tests/groups.rs b/tests/groups.rs index 0812852..5dbf627 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -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()