diff --git a/clap_generate/src/generators/mod.rs b/clap_generate/src/generators/mod.rs index e6872d19..8a8a3b15 100644 --- a/clap_generate/src/generators/mod.rs +++ b/clap_generate/src/generators/mod.rs @@ -61,11 +61,7 @@ pub trait Generator { fn all_subcommands(app: &App) -> Vec<(String, String)> { let mut subcmds: Vec<_> = Self::subcommands(app); - for sc_v in app - .get_subcommands() - .iter() - .map(|s| Self::all_subcommands(&s)) - { + for sc_v in app.get_subcommands().map(|s| Self::all_subcommands(&s)) { subcmds.extend(sc_v); } @@ -123,7 +119,6 @@ pub trait Generator { let mut shorts: Vec = p .get_arguments() - .iter() .filter_map(|a| { if a.get_index().is_none() && a.get_short().is_some() { Some(a.get_short().unwrap()) @@ -151,7 +146,6 @@ pub trait Generator { let mut longs: Vec = p .get_arguments() - .iter() .filter_map(|a| { if a.get_index().is_none() && a.get_long().is_some() { Some(a.get_long().unwrap().to_string()) diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index e98e04a4..6cf4c998 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -133,34 +133,33 @@ impl<'b> App<'b> { self.aliases.iter().map(|a| a.0) } - /// Get the list of subcommands + /// Iterate through the set of subcommands. #[inline] - pub fn get_subcommands(&self) -> &[App<'b>] { - &self.subcommands + pub fn get_subcommands(&self) -> impl Iterator> { + self.subcommands.iter() } - /// Get the list of subcommands + /// Iterate through the set of subcommands, getting a mutable reference to each. #[inline] - pub fn get_subcommands_mut(&mut self) -> &mut [App<'b>] { - &mut self.subcommands + pub fn get_subcommands_mut(&mut self) -> impl Iterator> { + self.subcommands.iter_mut() } - /// Get the list of arguments + /// Iterate through the set of arguments #[inline] - pub fn get_arguments(&self) -> &[Arg<'b>] { - &self.args.args + pub fn get_arguments(&self) -> impl Iterator> { + self.args.args.iter() } /// Get the list of *positional* arguments. #[inline] pub fn get_positionals(&self) -> impl Iterator> { - self.get_arguments().iter().filter(|a| a.is_positional()) + self.get_arguments().filter(|a| a.is_positional()) } /// Iterate through the *flags* that don't have custom heading. pub fn get_flags_no_heading(&self) -> impl Iterator> { self.get_arguments() - .iter() .filter(|a| !a.is_set(ArgSettings::TakesValue) && a.get_index().is_none()) .filter(|a| a.get_help_heading().is_none()) } @@ -168,7 +167,6 @@ impl<'b> App<'b> { /// Iterate through the *options* that don't have custom heading. pub fn get_opts_no_heading(&self) -> impl Iterator> { self.get_arguments() - .iter() .filter(|a| a.is_set(ArgSettings::TakesValue) && a.get_index().is_none()) .filter(|a| a.get_help_heading().is_none()) } @@ -209,7 +207,7 @@ impl<'b> App<'b> { where T: PartialEq + ?Sized, { - self.get_subcommands().iter().find(|s| s.aliases_to(name)) + self.get_subcommands().find(|s| s.aliases_to(name)) } } @@ -2035,9 +2033,8 @@ impl<'b> App<'b> { /// Iterate through all the names of all subcommands (not recursively), including aliases. /// Used for suggestions. pub(crate) fn all_subcommand_names(&self) -> impl Iterator { - self.get_subcommands().iter().map(|s| s.get_name()).chain( + self.get_subcommands().map(|s| s.get_name()).chain( self.get_subcommands() - .iter() .flat_map(|s| s.aliases.iter().map(|&(n, _)| n)), ) }