Add ability to get subparser by name from argparse
This commit is contained in:
parent
3db22a4e33
commit
a5859b0b05
15
lib/spack/external/argparse.py
vendored
15
lib/spack/external/argparse.py
vendored
@ -1708,6 +1708,21 @@ def _add_action(self, action):
|
|||||||
self._positionals._add_action(action)
|
self._positionals._add_action(action)
|
||||||
return 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):
|
def _get_optional_actions(self):
|
||||||
return [action
|
return [action
|
||||||
for action in self._actions
|
for action in self._actions
|
||||||
|
Loading…
Reference in New Issue
Block a user