diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index ed4d6100..c92c865f 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -94,7 +94,7 @@ pub struct App<'b> { pub(crate) subcommands: Vec>, pub(crate) replacers: HashMap<&'b str, &'b [&'b str]>, pub(crate) groups: Vec>, - pub(crate) help_headings: Vec>, + pub(crate) current_help_heading: Option<&'b str>, } impl<'b> App<'b> { @@ -690,14 +690,9 @@ impl<'b> App<'b> { /// ``` /// [argument]: ./struct.Arg.html pub fn arg>>(mut self, a: A) -> Self { - let help_heading: Option<&'b str> = if let Some(option_str) = self.help_headings.last() { - *option_str - } else { - None - }; let mut arg = a.into(); - if arg.get_help_heading().is_none() { - arg = arg.help_heading(help_heading); + if let Some(help_heading) = self.current_help_heading { + arg = arg.help_heading(Some(help_heading)); } self.args.push(arg); self @@ -708,14 +703,14 @@ impl<'b> App<'b> { /// call to help_heading #[inline] pub fn help_heading(mut self, heading: &'b str) -> Self { - self.help_headings.push(Some(heading)); + self.current_help_heading = Some(heading); self } /// Stop using custom section headings. #[inline] pub fn stop_custom_headings(mut self) -> Self { - self.help_headings.push(None); + self.current_help_heading = None; self }