@@ -101,9 +101,11 @@ pub struct Command {
101
101
subcommands : Vec < Command > ,
102
102
groups : Vec < ArgGroup > ,
103
103
current_help_heading : Option < Str > ,
104
+ current_subcommand_help_heading : Option < Str > ,
104
105
current_disp_ord : Option < usize > ,
105
106
subcommand_value_name : Option < Str > ,
106
107
subcommand_heading : Option < Str > ,
108
+ subcommand_help_heading : Option < Option < Str > > ,
107
109
external_value_parser : Option < super :: ValueParser > ,
108
110
long_help_exists : bool ,
109
111
deferred : Option < fn ( Command ) -> Command > ,
@@ -490,6 +492,7 @@ impl Command {
490
492
subcmd. disp_ord . get_or_insert ( current) ;
491
493
* current_disp_ord = current + 1 ;
492
494
}
495
+ subcmd. subcommand_help_heading . get_or_insert_with ( || self . current_subcommand_help_heading . clone ( ) ) ;
493
496
self . subcommands . push ( subcmd) ;
494
497
self
495
498
}
@@ -2295,6 +2298,32 @@ impl Command {
2295
2298
self
2296
2299
}
2297
2300
2301
+ /// Set the default section heading for future subcommands.
2302
+ ///
2303
+ /// This will be used for any subcommand that hasn't had [`Command::subcommand_help_heading`] called.
2304
+ ///
2305
+ /// This is useful if the default `Commands` heading is
2306
+ /// not specific enough for one's use case.
2307
+ ///
2308
+ /// [`Command::subcommand`]: Command::subcommand()
2309
+ /// [`Command::subcommand_help_heading`]: crate::Command::subcommand_help_heading()
2310
+ #[ inline]
2311
+ #[ must_use]
2312
+ pub fn next_subcommand_help_heading ( mut self , heading : impl IntoResettable < Str > ) -> Self {
2313
+ self . current_subcommand_help_heading = heading. into_resettable ( ) . into_option ( ) ;
2314
+ self
2315
+ }
2316
+
2317
+ /// Get the custom section heading specified via [`Command::next_subcommand_help_heading`].
2318
+ ///
2319
+ /// [`Command::subcommand_help_heading`]: Command::subcommand_help_heading()
2320
+ #[ inline]
2321
+ pub fn get_next_subcommand_help_heading ( & self ) -> Option < & str > {
2322
+ self . current_subcommand_help_heading . as_deref ( )
2323
+ }
2324
+
2325
+
2326
+
2298
2327
/// Change the starting value for assigning future display orders for args.
2299
2328
///
2300
2329
/// This will be used for any arg that hasn't had [`Arg::display_order`] called.
@@ -4889,6 +4918,14 @@ impl Command {
4889
4918
. any ( |sc| sc. name != "help" && !sc. is_set ( AppSettings :: Hidden ) )
4890
4919
}
4891
4920
4921
+ #[ cfg( any( feature = "usage" , feature = "help" ) ) ]
4922
+ pub ( crate ) fn needs_commands_header ( & self ) -> bool {
4923
+ self . subcommands
4924
+ . iter ( )
4925
+ . filter ( |sc| !sc. is_set ( AppSettings :: Hidden ) )
4926
+ . any ( |sc| sc. subcommand_help_heading . is_none ( ) )
4927
+ }
4928
+
4892
4929
/// Check if this subcommand can be referred to as `name`. In other words,
4893
4930
/// check if `name` is the name of this subcommand or is one of its aliases.
4894
4931
#[ inline]
@@ -5131,6 +5168,8 @@ impl Default for Command {
5131
5168
subcommands : Default :: default ( ) ,
5132
5169
groups : Default :: default ( ) ,
5133
5170
current_help_heading : Default :: default ( ) ,
5171
+ current_subcommand_help_heading : Default :: default ( ) ,
5172
+ subcommand_help_heading : Default :: default ( ) ,
5134
5173
current_disp_ord : Some ( 0 ) ,
5135
5174
subcommand_value_name : Default :: default ( ) ,
5136
5175
subcommand_heading : Default :: default ( ) ,
0 commit comments