Use shlex to split command args, add split_args property

This commit is contained in:
Florian Bruhin 2014-01-19 23:33:13 +01:00
parent 2d8fd4499d
commit bd28c00cf1
2 changed files with 11 additions and 2 deletions

View File

@ -4,10 +4,12 @@ from qutebrowser.commands.utils import Command
class Open(Command): class Open(Command):
nargs = 1 nargs = 1
key = 'o' key = 'o'
split_args = False
class TabOpen(Command): class TabOpen(Command):
nargs = 1 nargs = 1
key = 'O' key = 'O'
split_args = False
class TabClose(Command): class TabClose(Command):
nargs = 0 nargs = 0

View File

@ -21,14 +21,20 @@ class CommandParser(QObject):
error = pyqtSignal(str) error = pyqtSignal(str)
def parse(self, text): def parse(self, text):
parts = text.strip().split() parts = text.strip().split(maxsplit=1)
cmd = parts[0] cmd = parts[0]
args = parts[1:]
try: try:
obj = cmd_dict[cmd] obj = cmd_dict[cmd]
except KeyError: except KeyError:
self.error.emit("{}: no such command".format(cmd)) self.error.emit("{}: no such command".format(cmd))
return return
if obj.split_args:
args = shlex.split(parts[1])
else:
args = [parts[1]]
try: try:
obj.check(args) obj.check(args)
except TypeError: except TypeError:
@ -43,6 +49,7 @@ class Command(QObject):
signal = None signal = None
count = False count = False
bind = True bind = True
split_args = True
signal = pyqtSignal(tuple) signal = pyqtSignal(tuple)
def __init__(self): def __init__(self):