Bug 1381802 - [mach] Allow subcommands to use the 'parser' argument, r=gps

This allows subcommands to use external argument parsers.

MozReview-Commit-ID: 7TkbTff0Tv8

--HG--
extra : rebase_source : a1c245efa7ac7b28b974534b4cd2727c96f9219d
This commit is contained in:
Andrew Halberstadt 2017-07-18 08:53:13 -04:00
Родитель f64710a364
Коммит 2f253251a9
2 изменённых файлов: 5 добавлений и 4 удалений

Просмотреть файл

@ -255,9 +255,9 @@ class SubCommand(object):
description -- A textual description for this sub command.
"""
def __init__(self, command, subcommand, description=None):
def __init__(self, command, subcommand, description=None, parser=None):
self._mach_command = _MachCommand(name=command, subcommand=subcommand,
description=description)
description=description, parser=parser)
def __call__(self, func):
if not hasattr(func, '_mach_command'):

Просмотреть файл

@ -389,8 +389,9 @@ class CommandAction(argparse.Action):
subcommand = subcommand.pop()
subhandler = handler.subcommand_handlers[subcommand]
c_parser = argparse.ArgumentParser(add_help=False,
formatter_class=CommandFormatter)
c_parser = subhandler.parser or argparse.ArgumentParser(add_help=False)
c_parser.formatter_class = CommandFormatter
group = c_parser.add_argument_group('Sub Command Arguments')
self._populate_command_group(c_parser, subhandler, group)