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