Bug 1262495 - [mach] Allow running root commands that have subcommands on their own, r?gps
For example, say there is a command 'foo' that has a subcommand 'bar'. Prior to this, it was not
possible to run:
./mach foo
as its own independent command. The above would instead print the subcommand help for 'bar'.
MozReview-Commit-ID: JU4dXoxnCyu
--- a/python/mach/mach/dispatcher.py
+++ b/python/mach/mach/dispatcher.py
@@ -135,21 +135,18 @@ class CommandAction(argparse.Action):
handler = self._mach_registrar.command_handlers.get(command)
usage = '%(prog)s [global arguments] ' + command + \
' [command arguments]'
subcommand = None
# If there are sub-commands, parse the intent out immediately.
- if handler.subcommand_handlers:
- if not args:
- self._handle_subcommand_main_help(parser, handler)
- sys.exit(0)
- elif len(args) == 1 and args[0] in ('help', '--help'):
+ if handler.subcommand_handlers and args:
+ if len(args) == 1 and args[0] in ('help', '--help'):
self._handle_subcommand_main_help(parser, handler)
sys.exit(0)
# mach <command> help <subcommand>
elif len(args) == 2 and args[0] == 'help':
subcommand = args[1]
subhandler = handler.subcommand_handlers[subcommand]
self._handle_subcommand_help(parser, command, subcommand, subhandler)
sys.exit(0)