diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 0a1366ece..0cdf61945 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -336,7 +336,7 @@ class QuteBrowser(QApplication): logging.debug("maybe_quit quitting.") self.quit() - @cmdutils.register(instance='', split_args=False) + @cmdutils.register(instance='', maxsplit=0) def pyeval(self, s): """Evaluate a python string and display the results as a webpage. diff --git a/qutebrowser/browser/curcommand.py b/qutebrowser/browser/curcommand.py index b4126fdd7..396bac5d4 100644 --- a/qutebrowser/browser/curcommand.py +++ b/qutebrowser/browser/curcommand.py @@ -78,8 +78,7 @@ class CurCommandDispatcher(QObject): return frame.setScrollBarValue(orientation, int(m * perc / 100)) - @cmdutils.register(instance='mainwindow.tabs.cur', name='open', - split_args=False) + @cmdutils.register(instance='mainwindow.tabs.cur', name='open', maxsplit=0) def openurl(self, url, count=None): """Open an url in the current/[count]th tab. diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 6d52bf56c..0639cf2a3 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -30,7 +30,10 @@ class Command(QObject): Attributes: name: The main name of the command. - split_args: Whether to split the arguments or not. + maxsplit: Maximum count of splits to be made. + -1: Split everything (default) + 0: Don't split. + n: Split a maximum of n times. hide: Whether to hide the arguments or not. nargs: A (minargs, maxargs) tuple, maxargs = None if there's no limit. count: Whether the command supports a count, or not. @@ -51,11 +54,11 @@ class Command(QObject): signal = pyqtSignal(tuple) - def __init__(self, name, split_args, hide, nargs, count, desc, instance, + def __init__(self, name, maxsplit, hide, nargs, count, desc, instance, handler, completion): super().__init__() self.name = name - self.split_args = split_args + self.maxsplit = maxsplit self.hide = hide self.nargs = nargs self.count = count diff --git a/qutebrowser/commands/parsers.py b/qutebrowser/commands/parsers.py index 594029d3a..327f51a42 100644 --- a/qutebrowser/commands/parsers.py +++ b/qutebrowser/commands/parsers.py @@ -146,10 +146,8 @@ class CommandParser: if len(parts) == 1: args = [] - elif cmd.split_args: - args = parts[1].split() else: - args = [parts[1]] + args = parts[1].split(maxsplit=cmd.maxsplit) self._cmd = cmd self._args = args return [cmdstr] + args diff --git a/qutebrowser/commands/utils.py b/qutebrowser/commands/utils.py index bb36b5a19..622335e73 100644 --- a/qutebrowser/commands/utils.py +++ b/qutebrowser/commands/utils.py @@ -37,13 +37,16 @@ class register: # pylint: disable=invalid-name instance: The instance to be used as "self", as a dotted string. name: The name (as string) or names (as list) of the command. nargs: A (minargs, maxargs) tuple of valid argument counts, or an int. - split_args: Whether to split the arguments or not. + maxsplit: Maximum count of splits to be made. + -1: Split everything (default) + 0: Don't split. + n: Split a maximum of n times. hide: Whether to hide the command or not. completion: Which completion to use for arguments, as a list of strings. """ - def __init__(self, instance=None, name=None, nargs=None, split_args=True, + def __init__(self, instance=None, name=None, nargs=None, maxsplit=-1, hide=False, completion=None): """Save decorator arguments. @@ -53,7 +56,7 @@ class register: # pylint: disable=invalid-name See class attributes. """ self.name = name - self.split_args = split_args + self.maxsplit = maxsplit self.hide = hide self.nargs = nargs self.instance = instance @@ -84,7 +87,7 @@ class register: # pylint: disable=invalid-name names += name count, nargs = self._get_nargs_count(func) desc = func.__doc__.splitlines()[0].strip().rstrip('.') - cmd = Command(name=mainname, split_args=self.split_args, + cmd = Command(name=mainname, maxsplit=self.maxsplit, hide=self.hide, nargs=nargs, count=count, desc=desc, instance=self.instance, handler=func, completion=self.completion) diff --git a/qutebrowser/widgets/tabbedbrowser.py b/qutebrowser/widgets/tabbedbrowser.py index 3bca8b0b0..847e97ef3 100644 --- a/qutebrowser/widgets/tabbedbrowser.py +++ b/qutebrowser/widgets/tabbedbrowser.py @@ -210,7 +210,7 @@ class TabbedBrowser(TabWidget): elif last_close == 'blank': tab.openurl('about:blank') - @cmdutils.register(instance='mainwindow.tabs', split_args=False) + @cmdutils.register(instance='mainwindow.tabs', maxsplit=0) def tabopen(self, url): """Open a new tab with a given url.