From 2f253251a99630ea146f0b434495e4b124e1d10e Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Tue, 18 Jul 2017 08:53:13 -0400 Subject: [PATCH] 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 --- python/mach/mach/decorators.py | 4 ++-- python/mach/mach/dispatcher.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/python/mach/mach/decorators.py b/python/mach/mach/decorators.py index 6c1713d7f0ff..3351e048f29e 100644 --- a/python/mach/mach/decorators.py +++ b/python/mach/mach/decorators.py @@ -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'): diff --git a/python/mach/mach/dispatcher.py b/python/mach/mach/dispatcher.py index ae443e0e7030..7d6a2f2ffbde 100644 --- a/python/mach/mach/dispatcher.py +++ b/python/mach/mach/dispatcher.py @@ -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)