diff --git a/qutebrowser/commands/argparser.py b/qutebrowser/commands/argparser.py index 2aa704e1a..4e43259a1 100644 --- a/qutebrowser/commands/argparser.py +++ b/qutebrowser/commands/argparser.py @@ -22,10 +22,15 @@ import argparse +from PyQt5.QtCore import QCoreApplication, QUrl + from qutebrowser.commands import cmdexc from qutebrowser.utils import utils +SUPPRESS = argparse.SUPPRESS + + class ArgumentParserError(Exception): """Exception raised when the ArgumentParser signals an error.""" @@ -40,11 +45,20 @@ class ArgumentParserExit(Exception): super().__init__(msg) +class HelpAction(argparse.Action): + + def __call__(self, parser, _namespace, _values, _option_string=None): + QCoreApplication.instance().mainwindow.tabs.tabopen( + QUrl('qute:help/commands.html#{}'.format(parser.name))) + parser.exit() + + class ArgumentParser(argparse.ArgumentParser): """Subclass ArgumentParser to be more suitable for runtime parsing.""" - def __init__(self): + def __init__(self, name): + self.name = name super().__init__(add_help=False) def exit(self, status=0, msg=None): diff --git a/qutebrowser/commands/cmdutils.py b/qutebrowser/commands/cmdutils.py index 85e6480c3..4ecf9379a 100644 --- a/qutebrowser/commands/cmdutils.py +++ b/qutebrowser/commands/cmdutils.py @@ -167,6 +167,9 @@ class register: # pylint: disable=invalid-name if name in cmd_dict: raise ValueError("{} is already registered!".format(name)) self.parser = argparser.ArgumentParser(names[0]) + self.parser.add_argument('-h', '--help', action=argparser.HelpAction, + default=argparser.SUPPRESS, nargs=0, + help="Show this help message.") has_count, desc, type_conv = self._inspect_func() cmd = command.Command( name=names[0], split=self.split, hide=self.hide, count=has_count,