Skip to content

Commit

Permalink
feat: Implement App::find_subcommand_mut
Browse files Browse the repository at this point in the history
Similar to `App::find_subcommand`, except it returns a mutable reference
to the subcommand.
  • Loading branch information
sunshowers committed Jan 17, 2022
1 parent ccbbba8 commit 236ec97
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/build/app/mod.rs
Expand Up @@ -2246,6 +2246,18 @@ impl<'help> App<'help> {
self.get_subcommands().find(|s| s.aliases_to(name))
}

/// Find subcommand such that its name or one of aliases equals `name`, returning
/// a mutable reference to the subcommand.
///
/// This does not recurse through subcommands of subcommands.
#[inline]
pub fn find_subcommand_mut<T>(&mut self, name: &T) -> Option<&mut App<'help>>
where
T: PartialEq<str> + ?Sized,
{
self.get_subcommands_mut().find(|s| s.aliases_to(name))
}

/// Iterate through the set of arguments.
#[inline]
pub fn get_arguments(&self) -> impl Iterator<Item = &Arg<'help>> {
Expand Down

0 comments on commit 236ec97

Please sign in to comment.