diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2014-11-01 15:59:29 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2014-11-01 15:59:29 -0700 |
commit | a5859b0b051e5d48c9dca59502f2133dda8a255c (patch) | |
tree | 56fe15083e858514297ff35935c1b14cdd5ec67b | |
parent | 3db22a4e3317cb58e711efef71850eac85c4c48a (diff) | |
download | spack-a5859b0b051e5d48c9dca59502f2133dda8a255c.tar.gz spack-a5859b0b051e5d48c9dca59502f2133dda8a255c.tar.bz2 spack-a5859b0b051e5d48c9dca59502f2133dda8a255c.tar.xz spack-a5859b0b051e5d48c9dca59502f2133dda8a255c.zip |
Add ability to get subparser by name from argparse
-rw-r--r-- | lib/spack/external/argparse.py | 15 |
1 files changed, 15 insertions, 0 deletions
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 |