@@ -520,7 +520,7 @@ impl Subcommand {
520
520
print ! ( "{}" , config. list_heading) ;
521
521
}
522
522
523
- let groups = {
523
+ let recipe_groups = {
524
524
let mut groups = BTreeMap :: < Option < String > , Vec < & Recipe > > :: new ( ) ;
525
525
for recipe in module. public_recipes ( config) {
526
526
let recipe_groups = recipe. groups ( ) ;
@@ -535,17 +535,40 @@ impl Subcommand {
535
535
groups
536
536
} ;
537
537
538
+ let submodule_groups = {
539
+ let mut groups = BTreeMap :: < Option < String > , Vec < & Justfile > > :: new ( ) ;
540
+ for submodule in module. modules ( config) {
541
+ let submodule_groups = submodule. groups ( ) ;
542
+ if submodule_groups. is_empty ( ) {
543
+ groups. entry ( None ) . or_default ( ) . push ( submodule) ;
544
+ } else {
545
+ for group in submodule_groups {
546
+ groups
547
+ . entry ( Some ( group. to_string ( ) ) )
548
+ . or_default ( )
549
+ . push ( submodule) ;
550
+ }
551
+ }
552
+ }
553
+ groups
554
+ } ;
555
+
556
+ // ordered contains groups from both recipes and submodules by calling .public_groups()
538
557
let mut ordered = module
539
558
. public_groups ( config)
540
559
. into_iter ( )
541
560
. map ( Some )
542
561
. collect :: < Vec < Option < String > > > ( ) ;
543
562
544
- if groups . contains_key ( & None ) {
563
+ if recipe_groups . contains_key ( & None ) || submodule_groups . contains_key ( & None ) {
545
564
ordered. insert ( 0 , None ) ;
546
565
}
547
566
548
- let no_groups = groups. contains_key ( & None ) && groups. len ( ) == 1 ;
567
+ let no_groups = ordered. len ( ) == 1 && ordered. first ( ) == Some ( & None ) ;
568
+ let mut groups_count = 0 ;
569
+ if !no_groups {
570
+ groups_count = ordered. len ( ) ;
571
+ }
549
572
550
573
for ( i, group) in ordered. into_iter ( ) . enumerate ( ) {
551
574
if i > 0 {
@@ -561,69 +584,66 @@ impl Subcommand {
561
584
}
562
585
}
563
586
564
- for recipe in groups. get ( & group) . unwrap ( ) {
565
- for ( i, name) in iter:: once ( & recipe. name ( ) )
566
- . chain ( aliases. get ( recipe. name ( ) ) . unwrap_or ( & Vec :: new ( ) ) )
567
- . enumerate ( )
568
- {
569
- let doc = if i == 0 {
570
- recipe. doc ( ) . map ( Cow :: Borrowed )
571
- } else {
572
- Some ( Cow :: Owned ( format ! ( "alias for `{}`" , recipe. name) ) )
573
- } ;
574
-
575
- if let Some ( doc) = & doc {
576
- if doc. lines ( ) . count ( ) > 1 {
577
- for line in doc. lines ( ) {
578
- println ! (
579
- "{list_prefix}{} {}" ,
580
- config. color. stdout( ) . doc( ) . paint( "#" ) ,
581
- config. color. stdout( ) . doc( ) . paint( line) ,
582
- ) ;
587
+ if let Some ( recipes) = recipe_groups. get ( & group) {
588
+ for recipe in recipes {
589
+ for ( i, name) in iter:: once ( & recipe. name ( ) )
590
+ . chain ( aliases. get ( recipe. name ( ) ) . unwrap_or ( & Vec :: new ( ) ) )
591
+ . enumerate ( )
592
+ {
593
+ let doc = if i == 0 {
594
+ recipe. doc ( ) . map ( Cow :: Borrowed )
595
+ } else {
596
+ Some ( Cow :: Owned ( format ! ( "alias for `{}`" , recipe. name) ) )
597
+ } ;
598
+
599
+ if let Some ( doc) = & doc {
600
+ if doc. lines ( ) . count ( ) > 1 {
601
+ for line in doc. lines ( ) {
602
+ println ! (
603
+ "{list_prefix}{} {}" ,
604
+ config. color. stdout( ) . doc( ) . paint( "#" ) ,
605
+ config. color. stdout( ) . doc( ) . paint( line) ,
606
+ ) ;
607
+ }
583
608
}
584
609
}
585
- }
586
-
587
- print ! (
588
- "{list_prefix}{}" ,
589
- RecipeSignature { name, recipe } . color_display( config. color. stdout( ) )
590
- ) ;
591
610
592
- format_doc (
593
- config,
594
- name,
595
- doc. as_deref ( ) ,
596
- max_signature_width,
597
- & signature_widths,
598
- ) ;
611
+ print ! (
612
+ "{list_prefix}{}" ,
613
+ RecipeSignature { name, recipe } . color_display( config. color. stdout( ) )
614
+ ) ;
615
+
616
+ format_doc (
617
+ config,
618
+ name,
619
+ doc. as_deref ( ) ,
620
+ max_signature_width,
621
+ & signature_widths,
622
+ ) ;
623
+ }
599
624
}
600
625
}
601
- }
602
-
603
- if config. list_submodules {
604
- for ( i, submodule) in module. modules ( config) . into_iter ( ) . enumerate ( ) {
605
- if i + groups. len ( ) > 0 {
606
- println ! ( ) ;
607
- }
608
626
609
- println ! ( "{list_prefix}{}:" , submodule. name( ) ) ;
627
+ if let Some ( submodules) = submodule_groups. get ( & group) {
628
+ for ( i, submodule) in submodules. iter ( ) . enumerate ( ) {
629
+ if config. list_submodules {
630
+ if no_groups && ( i + groups_count > 0 ) {
631
+ println ! ( ) ;
632
+ }
633
+ println ! ( "{list_prefix}{}:" , submodule. name( ) ) ;
610
634
611
- Self :: list_module ( config, submodule, depth + 1 ) ;
612
- }
613
- } else {
614
- for ( i, submodule) in module. modules ( config) . into_iter ( ) . enumerate ( ) {
615
- if !no_groups && !groups. is_empty ( ) && i == 0 {
616
- println ! ( ) ;
635
+ Self :: list_module ( config, submodule, depth + 1 ) ;
636
+ } else {
637
+ print ! ( "{list_prefix}{} ..." , submodule. name( ) ) ;
638
+ format_doc (
639
+ config,
640
+ submodule. name ( ) ,
641
+ submodule. doc . as_deref ( ) ,
642
+ max_signature_width,
643
+ & signature_widths,
644
+ ) ;
645
+ }
617
646
}
618
-
619
- print ! ( "{list_prefix}{} ..." , submodule. name( ) ) ;
620
- format_doc (
621
- config,
622
- submodule. name ( ) ,
623
- submodule. doc . as_deref ( ) ,
624
- max_signature_width,
625
- & signature_widths,
626
- ) ;
627
647
}
628
648
}
629
649
}
0 commit comments