commands: Add initial --help argument support.

This commit is contained in:
Florian Bruhin 2014-09-04 17:59:50 +02:00
parent 32e24479b9
commit a656c8cfb0
2 changed files with 18 additions and 1 deletions

View File

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

View File

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