diff --git a/python/mach/mach/main.py b/python/mach/mach/main.py index 0980fbd1c82..c3bb588f171 100644 --- a/python/mach/mach/main.py +++ b/python/mach/mach/main.py @@ -21,6 +21,13 @@ from mozbuild.base import BuildConfig from mozbuild.config import ConfigSettings from mozbuild.logger import LoggingManager + +from mach.base import ( + CommandArgument, + CommandProvider, + Command, +) + from mach.registrar import populate_argument_parser @@ -112,6 +119,7 @@ class ArgumentParser(argparse.ArgumentParser): return text +@CommandProvider class Mach(object): """Contains code for the command-line `mach` interface.""" @@ -263,12 +271,18 @@ To see more help for a specific command, run: parser.print_usage() return 0 - if argv[0] == 'help': - parser.print_help() - return 0 - args = parser.parse_args(argv) + if args.command == 'help': + if args.subcommand is None: + parser.print_help() + return 0 + + # ArgumentParser doesn't seem to have a public API to expose the + # subparsers. So, we just simulate the behavior that causes + # ArgumentParser to do the printing for us. + return self._run([args.subcommand, '--help']) + # Add JSON logging to a file if requested. if args.logfile: self.log_manager.add_json_handler(args.logfile) @@ -436,3 +450,11 @@ To see more help for a specific command, run: populate_argument_parser(subparser) return parser + + @Command('help', help='Show mach usage info or help for a command.') + @CommandArgument('subcommand', default=None, nargs='?', + help='Command to show help info for.') + def _help(self, subcommand=None): + # The built-in handler doesn't pass the original ArgumentParser into + # handlers (yet). This command is currently handled by _run(). + assert False