diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-10-02 17:01:04 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-10-02 17:01:04 -0600 |
commit | e40dd3843f9abb9a8a0908159edfa0c69b90b1ab (patch) | |
tree | 1c97f33db03f3a20fbd3f3e5525218196cdf0636 | |
parent | 8f4f172ef66a9804ed26f9361e3c90b2c9c28970 (diff) | |
parent | d5f883ee45c9252454cd7a43917fa202fd231147 (diff) | |
download | servo-e40dd3843f9abb9a8a0908159edfa0c69b90b1ab.tar.gz servo-e40dd3843f9abb9a8a0908159edfa0c69b90b1ab.zip |
Auto merge of #7838 - mbrubeck:mach-up, r=mbrubeck
Upgrade to latest mach from mozilla-central
r? @jgraham
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7838)
<!-- Reviewable:end -->
-rw-r--r-- | python/mach/mach/dispatcher.py | 26 | ||||
-rw-r--r-- | python/mach/mach/registrar.py | 5 |
2 files changed, 25 insertions, 6 deletions
diff --git a/python/mach/mach/dispatcher.py b/python/mach/mach/dispatcher.py index 6a4916c0fa0..666c4a3f691 100644 --- a/python/mach/mach/dispatcher.py +++ b/python/mach/mach/dispatcher.py @@ -92,7 +92,6 @@ class CommandAction(argparse.Action): elif values: command = values[0].lower() args = values[1:] - if command == 'help': if args and args[0] not in ['-h', '--help']: # Make sure args[0] is indeed a command. @@ -102,8 +101,17 @@ class CommandAction(argparse.Action): sys.exit(0) elif '-h' in args or '--help' in args: # -h or --help is in the command arguments. - self._handle_command_help(parser, command) - sys.exit(0) + if '--' in args: + # -- is in command arguments + if '-h' in args[:args.index('--')] or '--help' in args[:args.index('--')]: + # Honor -h or --help only if it appears before -- + self._handle_command_help(parser, command) + sys.exit(0) + else: + self._handle_command_help(parser, command) + sys.exit(0) + + else: raise NoCommandError() @@ -172,14 +180,20 @@ class CommandAction(argparse.Action): 'usage': usage, } + remainder = None + if handler.parser: subparser = handler.parser subparser.context = self._context + for arg in subparser._actions[:]: + if arg.nargs == argparse.REMAINDER: + subparser._actions.remove(arg) + remainder = (arg.dest,), {'default': arg.default, + 'nargs': arg.nargs, + 'help': arg.help} else: subparser = argparse.ArgumentParser(**parser_args) - remainder = None - for arg in handler.arguments: # Remove our group keyword; it's not needed here. group_name = arg[1].get('group') @@ -230,7 +244,7 @@ class CommandAction(argparse.Action): setattr(command_namespace, name, extra) else: setattr(command_namespace, name, options.get('default', [])) - elif extra: + elif extra and handler.cls.__name__ != 'DeprecatedCommands': raise UnrecognizedArgumentError(command, extra) def _handle_main_help(self, parser, verbose): diff --git a/python/mach/mach/registrar.py b/python/mach/mach/registrar.py index 49c41bf97bf..522f761dcee 100644 --- a/python/mach/mach/registrar.py +++ b/python/mach/mach/registrar.py @@ -61,6 +61,11 @@ class MachRegistrar(object): if handler.pass_context and not context: raise Exception('mach command class requires context.') + if context: + prerun = getattr(context, 'pre_dispatch_handler', None) + if prerun: + prerun(context, handler, args=kwargs) + if handler.pass_context: instance = cls(context) else: |