mirror of
https://github.com/derrod/legendary.git
synced 2024-09-30 01:08:31 +13:00
58bd76c39e
I don't want to break people's muscle memory, but I also don't want to have the help output be messier than it needs to be.
28 lines
984 B
Python
28 lines
984 B
Python
import argparse
|
|
|
|
|
|
class HiddenAliasSubparsersAction(argparse._SubParsersAction):
|
|
def add_parser(self, name, **kwargs):
|
|
# set prog from the existing prefix
|
|
if kwargs.get('prog') is None:
|
|
kwargs['prog'] = '%s %s' % (self._prog_prefix, name)
|
|
|
|
aliases = kwargs.pop('aliases', ())
|
|
hide_aliases = kwargs.pop('hide_aliases', False)
|
|
|
|
# create a pseudo-action to hold the choice help
|
|
if 'help' in kwargs:
|
|
help = kwargs.pop('help')
|
|
_aliases = None if hide_aliases else aliases
|
|
choice_action = self._ChoicesPseudoAction(name, _aliases, help)
|
|
self._choices_actions.append(choice_action)
|
|
|
|
# create the parser and add it to the map
|
|
parser = self._parser_class(**kwargs)
|
|
self._name_parser_map[name] = parser
|
|
|
|
# make parser available under aliases also
|
|
for alias in aliases:
|
|
self._name_parser_map[alias] = parser
|
|
|
|
return parser
|