Rename parse_check_run to run in CommandParser
This commit is contained in:
parent
8e71f0cb8c
commit
226adac899
@ -44,8 +44,7 @@ class QuteBrowser(QApplication):
|
||||
self.aboutToQuit.connect(self.config.save)
|
||||
self.mainwindow.tabs.keypress.connect(self.keyparser.handle)
|
||||
self.keyparser.set_cmd_text.connect(self.mainwindow.status.cmd.set_cmd)
|
||||
self.mainwindow.status.cmd.got_cmd.connect(
|
||||
self.commandparser.parse_check_run)
|
||||
self.mainwindow.status.cmd.got_cmd.connect(self.commandparser.run)
|
||||
self.mainwindow.status.cmd.got_cmd.connect(
|
||||
self.mainwindow.tabs.setFocus)
|
||||
self.commandparser.error.connect(self.mainwindow.status.disp_error)
|
||||
|
@ -87,8 +87,7 @@ class KeyParser(QObject):
|
||||
count = int(countstr) if countstr else None
|
||||
|
||||
try:
|
||||
self.commandparser.parse_check_run(cmdstr_hay, count=count,
|
||||
ignore_exc=False)
|
||||
self.commandparser.run(cmdstr_hay, count=count, ignore_exc=False)
|
||||
except NoSuchCommandError:
|
||||
return
|
||||
except ArgumentCountError:
|
||||
|
@ -37,8 +37,8 @@ class CommandParser(QObject):
|
||||
args = []
|
||||
error = pyqtSignal(str) # Emitted if there's an error
|
||||
|
||||
def parse(self, text):
|
||||
"""Parses a command and runs its handler"""
|
||||
def _parse(self, text):
|
||||
"""Parses a command"""
|
||||
self.text = text
|
||||
parts = self.text.strip().split(maxsplit=1)
|
||||
cmdstr = parts[0]
|
||||
@ -57,29 +57,29 @@ class CommandParser(QObject):
|
||||
self.cmd = cmd
|
||||
self.args = args
|
||||
|
||||
def check(self):
|
||||
def _check(self):
|
||||
try:
|
||||
self.cmd.check(self.args)
|
||||
except ArgumentCountError:
|
||||
self.error.emit("{}: invalid argument count".format(self.cmd))
|
||||
raise
|
||||
|
||||
def run(self, count=None):
|
||||
def _run(self, count=None):
|
||||
if count is not None:
|
||||
self.cmd.run(self.args, count=count)
|
||||
else:
|
||||
self.cmd.run(self.args)
|
||||
|
||||
def parse_check_run(self, text, count=None, ignore_exc=True):
|
||||
def run(self, text, count=None, ignore_exc=True):
|
||||
try:
|
||||
self.parse(text)
|
||||
self.check()
|
||||
self._parse(text)
|
||||
self._check()
|
||||
except (ArgumentCountError, NoSuchCommandError):
|
||||
if ignore_exc:
|
||||
return
|
||||
else:
|
||||
raise
|
||||
self.run(count=count)
|
||||
self._run(count=count)
|
||||
|
||||
class Command(QObject):
|
||||
"""Base skeleton for a command. See the module help for
|
||||
|
Loading…
Reference in New Issue
Block a user