Bug 995847 - Add -h and --help support to mach. r=glandium

* |mach --help| prints the global help message as |mach help|.
* |mach command --help| prints the command help message as
  |mach help command|.
This commit is contained in:
Ting-Yu Lin
2014-05-06 19:10:00 +02:00
parent 1cd97b05a2
commit 4f33718fa7
2 changed files with 23 additions and 12 deletions

View File

@@ -83,19 +83,27 @@ class CommandAction(argparse.Action):
into that parser. We then merge the results with the main
ArgumentParser.
"""
if not values:
raise NoCommandError()
if namespace.help:
# -h or --help is in the global arguments.
self._handle_main_help(parser)
sys.exit(0)
elif values:
command = values[0].lower()
args = values[1:]
if command == 'help':
if len(args):
if args and args[0] not in ['-h', '--help']:
# Make sure args[0] is indeed a command.
self._handle_subcommand_help(parser, args[0])
else:
self._handle_main_help(parser)
sys.exit(0)
elif '-h' in args or '--help' in args:
# -h or --help is in the command arguments.
self._handle_subcommand_help(parser, command)
sys.exit(0)
else:
raise NoCommandError()
handler = self._mach_registrar.command_handlers.get(command)

View File

@@ -567,6 +567,9 @@ To see more help for a specific command, run:
action='store_true', default=False,
help='Do not prefix log lines with times. By default, mach will '
'prefix each output line with the time since command start.')
global_group.add_argument('-h', '--help', dest='help',
action='store_true', default=False,
help='Show this help message.')
for args, kwargs in self.global_arguments:
global_group.add_argument(*args, **kwargs)