commands: Add initial --help argument support.
This commit is contained in:
parent
32e24479b9
commit
a656c8cfb0
@ -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):
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user