From a5859b0b051e5d48c9dca59502f2133dda8a255c Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 1 Nov 2014 15:59:29 -0700 Subject: Add ability to get subparser by name from argparse --- lib/spack/external/argparse.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/spack/external/argparse.py b/lib/spack/external/argparse.py index 42b64ee7be..394e5da152 100644 --- a/lib/spack/external/argparse.py +++ b/lib/spack/external/argparse.py @@ -1708,6 +1708,21 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): self._positionals._add_action(action) return action + + def get_subparser(self, name): + """Gets a subparser added with the supplied name. + This is an extension to the standard argparse API. + """ + subpasrsers_actions = [ + action for action in self._actions + if isinstance(action, _SubParsersAction)] + for action in subpasrsers_actions: + for choice, subparser in action.choices.items(): + if choice == name: + return subparser + return None + + def _get_optional_actions(self): return [action for action in self._actions -- cgit v1.2.3-70-g09d2