Bug 799312 - Implement |mach help <command>|; r=jhammel

Previously you had to |mach <command> --help|. Both forms now work.
This commit is contained in:
Gregory Szorc 2012-10-10 11:08:09 -07:00
parent ca38f7a4a6
commit 4e06481823

View File

@ -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