Skip to content

Commit d29ec74

Browse files
committed
feat: Add help_heading to command
- allows setting a custom help heading for the command - implements getter for help heading
1 parent 44929b6 commit d29ec74

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

clap_builder/src/builder/command.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub struct Command {
104104
current_disp_ord: Option<usize>,
105105
subcommand_value_name: Option<Str>,
106106
subcommand_heading: Option<Str>,
107+
help_heading: Option<Option<Str>>,
107108
external_value_parser: Option<super::ValueParser>,
108109
long_help_exists: bool,
109110
deferred: Option<fn(Command) -> Command>,
@@ -3701,6 +3702,24 @@ impl Command {
37013702
self.subcommand_heading = heading.into_resettable().into_option();
37023703
self
37033704
}
3705+
3706+
3707+
/// Set a custom help_heading for the command
3708+
#[inline]
3709+
#[must_use]
3710+
pub fn help_heading(mut self, heading: impl IntoResettable<Str>) -> Self {
3711+
self.help_heading = Some(heading.into_resettable().into_option());
3712+
self
3713+
}
3714+
3715+
/// Get the help heading specified for this argument, if any
3716+
#[inline]
3717+
pub fn get_help_heading(&self) -> Option<&str> {
3718+
self.help_heading
3719+
.as_ref()
3720+
.map(|s| s.as_deref())
3721+
.unwrap_or_default()
3722+
}
37043723
}
37053724

37063725
/// # Reflection
@@ -4229,7 +4248,7 @@ impl Command {
42294248
pub fn is_hide_set(&self) -> bool {
42304249
self.is_set(AppSettings::Hidden)
42314250
}
4232-
4251+
42334252
/// Report whether [`Command::subcommand_required`] is set
42344253
pub fn is_subcommand_required_set(&self) -> bool {
42354254
self.is_set(AppSettings::SubcommandRequired)
@@ -5218,6 +5237,7 @@ impl Default for Command {
52185237
current_disp_ord: Some(0),
52195238
subcommand_value_name: Default::default(),
52205239
subcommand_heading: Default::default(),
5240+
help_heading: Default::default(),
52215241
external_value_parser: Default::default(),
52225242
long_help_exists: false,
52235243
deferred: None,

0 commit comments

Comments
 (0)