Clean up CommandRunner.parse
This commit is contained in:
parent
3e22f64a20
commit
009fbe8213
@ -150,6 +150,15 @@ class CommandRunner(QObject):
|
|||||||
count = None
|
count = None
|
||||||
return (count, cmdstr)
|
return (count, cmdstr)
|
||||||
|
|
||||||
|
def _parse_fallback(self, text, count, keep):
|
||||||
|
"""Parse the given commandline without a valid command."""
|
||||||
|
if keep:
|
||||||
|
cmdstr, sep, argstr = text.partition(' ')
|
||||||
|
cmdline = [cmdstr, sep] + argstr.split()
|
||||||
|
else:
|
||||||
|
cmdline = text.split()
|
||||||
|
return ParseResult(cmd=None, args=None, cmdline=cmdline, count=count)
|
||||||
|
|
||||||
def parse(self, text, *, aliases=True, fallback=False, keep=False):
|
def parse(self, text, *, aliases=True, fallback=False, keep=False):
|
||||||
"""Split the commandline text into command and arguments.
|
"""Split the commandline text into command and arguments.
|
||||||
|
|
||||||
@ -168,6 +177,7 @@ class CommandRunner(QObject):
|
|||||||
|
|
||||||
if not cmdstr and not fallback:
|
if not cmdstr and not fallback:
|
||||||
raise cmdexc.NoSuchCommandError("No command given")
|
raise cmdexc.NoSuchCommandError("No command given")
|
||||||
|
|
||||||
if aliases:
|
if aliases:
|
||||||
new_cmd = self._get_alias(text)
|
new_cmd = self._get_alias(text)
|
||||||
if new_cmd is not None:
|
if new_cmd is not None:
|
||||||
@ -181,18 +191,11 @@ class CommandRunner(QObject):
|
|||||||
try:
|
try:
|
||||||
cmd = cmdutils.cmd_dict[cmdstr]
|
cmd = cmdutils.cmd_dict[cmdstr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if fallback:
|
if not fallback:
|
||||||
cmd = None
|
raise cmdexc.NoSuchCommandError(
|
||||||
args = None
|
'{}: no such command'.format(cmdstr))
|
||||||
if keep:
|
return self._parse_fallback(text, count, keep)
|
||||||
cmdstr, sep, argstr = text.partition(' ')
|
|
||||||
cmdline = [cmdstr, sep] + argstr.split()
|
|
||||||
else:
|
|
||||||
cmdline = text.split()
|
|
||||||
else:
|
|
||||||
raise cmdexc.NoSuchCommandError('{}: no such command'.format(
|
|
||||||
cmdstr))
|
|
||||||
else:
|
|
||||||
args = self._split_args(cmd, argstr, keep)
|
args = self._split_args(cmd, argstr, keep)
|
||||||
if keep and args:
|
if keep and args:
|
||||||
cmdline = [cmdstr, sep + args[0]] + args[1:]
|
cmdline = [cmdstr, sep + args[0]] + args[1:]
|
||||||
@ -200,6 +203,7 @@ class CommandRunner(QObject):
|
|||||||
cmdline = [cmdstr, sep]
|
cmdline = [cmdstr, sep]
|
||||||
else:
|
else:
|
||||||
cmdline = [cmdstr] + args[:]
|
cmdline = [cmdstr] + args[:]
|
||||||
|
|
||||||
return ParseResult(cmd=cmd, args=args, cmdline=cmdline, count=count)
|
return ParseResult(cmd=cmd, args=args, cmdline=cmdline, count=count)
|
||||||
|
|
||||||
def _completion_match(self, cmdstr):
|
def _completion_match(self, cmdstr):
|
||||||
|
Loading…
Reference in New Issue
Block a user