Add a cmdutils.check_exclusive function.
This commit is contained in:
parent
18f84c5cbc
commit
d8a917575d
@ -115,9 +115,8 @@ class CommandDispatcher:
|
|||||||
errstr += " - {}".format(url.errorString())
|
errstr += " - {}".format(url.errorString())
|
||||||
raise cmdexc.CommandError(errstr)
|
raise cmdexc.CommandError(errstr)
|
||||||
tabbed_browser = self._tabbed_browser()
|
tabbed_browser = self._tabbed_browser()
|
||||||
if sum(1 for e in (tab, background, window) if e) > 1:
|
cmdutils.check_exclusive((tab, background, window), 'tbw')
|
||||||
raise cmdexc.CommandError("Only one of -t/-b/-w can be given!")
|
if window:
|
||||||
elif window:
|
|
||||||
tabbed_browser = self._tabbed_browser(window=True)
|
tabbed_browser = self._tabbed_browser(window=True)
|
||||||
tabbed_browser.tabopen(url)
|
tabbed_browser.tabopen(url)
|
||||||
elif tab:
|
elif tab:
|
||||||
@ -229,8 +228,7 @@ class CommandDispatcher:
|
|||||||
QTabBar.SelectLeftTab, QTabBar.SelectRightTab, or None if no change
|
QTabBar.SelectLeftTab, QTabBar.SelectRightTab, or None if no change
|
||||||
should be made.
|
should be made.
|
||||||
"""
|
"""
|
||||||
if sum(1 for e in (left, right, opposite) if e) > 1:
|
cmdutils.check_exclusive((left, right, opposite), 'lro')
|
||||||
raise cmdexc.CommandError("Only one of -l/-r/-o can be given!")
|
|
||||||
if left:
|
if left:
|
||||||
return QTabBar.SelectLeftTab
|
return QTabBar.SelectLeftTab
|
||||||
elif right:
|
elif right:
|
||||||
@ -488,8 +486,7 @@ class CommandDispatcher:
|
|||||||
bg: Open in a background tab.
|
bg: Open in a background tab.
|
||||||
window: Open in a new window.
|
window: Open in a new window.
|
||||||
"""
|
"""
|
||||||
if sum(1 for e in (tab, bg, window) if e) > 1:
|
cmdutils.check_exclusive((tab, bg, window), 'tbw')
|
||||||
raise cmdexc.CommandError("Only one of -t/-b/-w can be given!")
|
|
||||||
widget = self._current_widget()
|
widget = self._current_widget()
|
||||||
frame = widget.page().currentFrame()
|
frame = widget.page().currentFrame()
|
||||||
url = self._current_url()
|
url = self._current_url()
|
||||||
|
@ -82,6 +82,21 @@ def arg_or_count(arg, count, default=None, countzero=None):
|
|||||||
raise ValueError("Either count or argument have to be set!")
|
raise ValueError("Either count or argument have to be set!")
|
||||||
|
|
||||||
|
|
||||||
|
def check_exclusive(flags, names):
|
||||||
|
"""Check if only one flag is set with exclusive flags.
|
||||||
|
|
||||||
|
Raise a CommandError if not.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
flags: An iterable of booleans to check.
|
||||||
|
names: An iterable of flag names for the error message.
|
||||||
|
"""
|
||||||
|
if sum(1 for e in flags if e) > 1:
|
||||||
|
argstr = '/'.join('-' + e for e in names)
|
||||||
|
raise cmdexc.CommandError("Only one of {} can be given!".format(
|
||||||
|
argstr))
|
||||||
|
|
||||||
|
|
||||||
class register: # pylint: disable=invalid-name
|
class register: # pylint: disable=invalid-name
|
||||||
|
|
||||||
"""Decorator to register a new command handler.
|
"""Decorator to register a new command handler.
|
||||||
|
Loading…
Reference in New Issue
Block a user