@@ -478,12 +478,17 @@ impl Subcommand {
478478 } ) ?;
479479 }
480480
481- Self :: list_module ( config, module , 0 ) ;
481+ Self :: list_module ( config, 0 , & config . groups , module ) ? ;
482482
483483 Ok ( ( ) )
484484 }
485485
486- fn list_module ( config : & Config , module : & Justfile , depth : usize ) {
486+ fn list_module (
487+ config : & Config ,
488+ depth : usize ,
489+ groups : & [ String ] ,
490+ module : & Justfile ,
491+ ) -> RunResult < ' static > {
487492 fn print_doc_and_aliases (
488493 config : & Config ,
489494 name : & str ,
@@ -597,54 +602,76 @@ impl Subcommand {
597602
598603 let list_prefix = config. list_prefix . repeat ( depth + 1 ) ;
599604
605+ if !groups. is_empty ( ) {
606+ let public_groups = module. public_groups ( config) ;
607+ for group in groups {
608+ if !public_groups. contains ( group) {
609+ return Err ( Error :: UnknownGroup {
610+ group : group. clone ( ) ,
611+ } ) ;
612+ }
613+ }
614+ }
615+
600616 if depth == 0 {
601617 print ! ( "{}" , config. list_heading) ;
602618 }
603619
604620 let recipe_groups = {
605- let mut groups = BTreeMap :: < Option < String > , Vec < & Recipe > > :: new ( ) ;
621+ let mut recipe_groups = BTreeMap :: < Option < String > , Vec < & Recipe > > :: new ( ) ;
606622 for recipe in module. public_recipes ( config) {
607- let recipe_groups = recipe. groups ( ) ;
608- if recipe_groups . is_empty ( ) {
609- groups . entry ( None ) . or_default ( ) . push ( recipe) ;
623+ let recipe_groups_list = recipe. groups ( ) ;
624+ if recipe_groups_list . is_empty ( ) {
625+ recipe_groups . entry ( None ) . or_default ( ) . push ( recipe) ;
610626 } else {
611- for group in recipe_groups {
612- groups . entry ( Some ( group) ) . or_default ( ) . push ( recipe) ;
627+ for group in recipe_groups_list {
628+ recipe_groups . entry ( Some ( group) ) . or_default ( ) . push ( recipe) ;
613629 }
614630 }
615631 }
616- groups
632+ recipe_groups
617633 } ;
618634
619635 let submodule_groups = {
620- let mut groups = BTreeMap :: < Option < String > , Vec < & Justfile > > :: new ( ) ;
636+ let mut submodule_groups = BTreeMap :: < Option < String > , Vec < & Justfile > > :: new ( ) ;
621637 for submodule in module. public_modules ( config) {
622- let submodule_groups = submodule. groups ( ) ;
623- if submodule_groups . is_empty ( ) {
624- groups . entry ( None ) . or_default ( ) . push ( submodule) ;
638+ let submodule_groups_list = submodule. groups ( ) ;
639+ if submodule_groups_list . is_empty ( ) {
640+ submodule_groups . entry ( None ) . or_default ( ) . push ( submodule) ;
625641 } else {
626- for group in submodule_groups {
627- groups
642+ for group in submodule_groups_list {
643+ submodule_groups
628644 . entry ( Some ( group. to_string ( ) ) )
629645 . or_default ( )
630646 . push ( submodule) ;
631647 }
632648 }
633649 }
634- groups
650+ submodule_groups
635651 } ;
636652
637- let mut ordered_groups = module
638- . public_groups ( config)
639- . into_iter ( )
640- . map ( Some )
641- . collect :: < Vec < Option < String > > > ( ) ;
653+ let mut ordered_groups = if groups. is_empty ( ) {
654+ module
655+ . public_groups ( config)
656+ . into_iter ( )
657+ . map ( Some )
658+ . collect :: < Vec < Option < String > > > ( )
659+ } else {
660+ groups
661+ . iter ( )
662+ . cloned ( )
663+ . map ( Some )
664+ . collect :: < Vec < Option < String > > > ( )
665+ } ;
642666
643- if recipe_groups. contains_key ( & None ) || submodule_groups. contains_key ( & None ) {
667+ if groups. is_empty ( )
668+ && ( recipe_groups. contains_key ( & None ) || submodule_groups. contains_key ( & None ) )
669+ {
644670 ordered_groups. insert ( 0 , None ) ;
645671 }
646672
647- let no_groups = ordered_groups. len ( ) == 1 && ordered_groups. first ( ) == Some ( & None ) ;
673+ let no_groups =
674+ groups. is_empty ( ) && ordered_groups. len ( ) == 1 && ordered_groups. first ( ) == Some ( & None ) ;
648675
649676 let groups_count = if no_groups { 0 } else { ordered_groups. len ( ) } ;
650677
@@ -720,7 +747,7 @@ impl Subcommand {
720747 }
721748 println ! ( "{list_prefix}{}:" , submodule. name( ) ) ;
722749
723- Self :: list_module ( config, submodule , depth + 1 ) ;
750+ Self :: list_module ( config, depth + 1 , & [ ] , submodule ) ? ;
724751 } else {
725752 print ! ( "{list_prefix}{} ..." , submodule. name( ) ) ;
726753 print_doc_and_aliases (
@@ -735,6 +762,8 @@ impl Subcommand {
735762 }
736763 }
737764 }
765+
766+ Ok ( ( ) )
738767 }
739768
740769 fn show < ' src > ( config : & Config , module : & Justfile < ' src > , path : & ModulePath ) -> RunResult < ' src > {
0 commit comments