From 236ec973d95e02c8440ee0da6e6c5713389ffc71 Mon Sep 17 00:00:00 2001 From: Rain Date: Mon, 17 Jan 2022 12:21:27 -0800 Subject: [PATCH] feat: Implement App::find_subcommand_mut Similar to `App::find_subcommand`, except it returns a mutable reference to the subcommand. --- src/build/app/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index ddad73f4f97..d3fd35e8cd6 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -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(&mut self, name: &T) -> Option<&mut App<'help>> + where + T: PartialEq + ?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> {