Rename --url to --pattern

This commit is contained in:
Florian Bruhin 2018-02-20 17:55:40 +01:00
parent f8b1e7739d
commit a3dfec20c1
3 changed files with 19 additions and 17 deletions

View File

@ -274,7 +274,7 @@ Set all settings back to their default.
[[config-cycle]]
=== config-cycle
Syntax: +:config-cycle [*--url* 'url'] [*--temp*] [*--print*]
Syntax: +:config-cycle [*--pattern* 'pattern'] [*--temp*] [*--print*]
'option' ['values' ['values' ...]]+
Cycle an option between multiple values.
@ -284,7 +284,7 @@ Cycle an option between multiple values.
* +'values'+: The values to cycle through.
==== optional arguments
* +*-u*+, +*--url*+: The URL pattern to use.
* +*-u*+, +*--pattern*+: The URL pattern to use.
* +*-t*+, +*--temp*+: Set value temporarily until qutebrowser is closed.
* +*-p*+, +*--print*+: Print the value after setting.
@ -1112,7 +1112,7 @@ Save a session.
[[set]]
=== set
Syntax: +:set [*--temp*] [*--print*] [*--url* 'url'] ['option'] ['value']+
Syntax: +:set [*--temp*] [*--print*] [*--pattern* 'pattern'] ['option'] ['value']+
Set an option.
@ -1125,7 +1125,7 @@ If the option name ends with '?', the value of the option is shown instead. Usin
==== optional arguments
* +*-t*+, +*--temp*+: Set value temporarily until qutebrowser is closed.
* +*-p*+, +*--print*+: Print the value after setting.
* +*-u*+, +*--url*+: The URL pattern to use.
* +*-u*+, +*--pattern*+: The URL pattern to use.
[[set-cmd-text]]
=== set-cmd-text

View File

@ -47,16 +47,16 @@ class ConfigCommands:
except configexc.Error as e:
raise cmdexc.CommandError(str(e))
def _parse_pattern(self, url):
"""Parse an URL argument to a pattern."""
if url is None:
def _parse_pattern(self, pattern):
"""Parse a pattern string argument to a pattern."""
if pattern is None:
return None
try:
return urlmatch.UrlPattern(url)
return urlmatch.UrlPattern(pattern)
except urlmatch.ParseError as e:
raise cmdexc.CommandError("Error while parsing {}: {}"
.format(url, str(e)))
.format(pattern, str(e)))
def _print_value(self, option, pattern):
"""Print the value of the given option."""
@ -68,8 +68,9 @@ class ConfigCommands:
@cmdutils.argument('option', completion=configmodel.option)
@cmdutils.argument('value', completion=configmodel.value)
@cmdutils.argument('win_id', win_id=True)
@cmdutils.argument('pattern', flag='u')
def set(self, win_id, option=None, value=None, temp=False, print_=False,
*, url=None):
*, pattern=None):
"""Set an option.
If the option name ends with '?', the value of the option is shown
@ -81,7 +82,7 @@ class ConfigCommands:
Args:
option: The name of the option.
value: The value to set.
url: The URL pattern to use.
pattern: The URL pattern to use.
temp: Set value temporarily until qutebrowser is closed.
print_: Print the value after setting.
"""
@ -95,7 +96,7 @@ class ConfigCommands:
raise cmdexc.CommandError("Toggling values was moved to the "
":config-cycle command")
pattern = self._parse_pattern(url)
pattern = self._parse_pattern(pattern)
if option.endswith('?') and option != '?':
self._print_value(option[:-1], pattern=pattern)
@ -177,18 +178,19 @@ class ConfigCommands:
@cmdutils.register(instance='config-commands', star_args_optional=True)
@cmdutils.argument('option', completion=configmodel.option)
@cmdutils.argument('values', completion=configmodel.value)
def config_cycle(self, option, *values, url=None, temp=False,
@cmdutils.argument('pattern', flag='u')
def config_cycle(self, option, *values, pattern=None, temp=False,
print_=False):
"""Cycle an option between multiple values.
Args:
option: The name of the option.
values: The values to cycle through.
url: The URL pattern to use.
pattern: The URL pattern to use.
temp: Set value temporarily until qutebrowser is closed.
print_: Print the value after setting.
"""
pattern = self._parse_pattern(url)
pattern = self._parse_pattern(pattern)
with self._handle_config_error():
opt = self._config.get_opt(option)

View File

@ -90,7 +90,7 @@ class TestSet:
monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit)
option = 'content.javascript.enabled'
commands.set(0, option, 'false', url='*://example.com')
commands.set(0, option, 'false', pattern='*://example.com')
pattern = urlmatch.UrlPattern('*://example.com')
assert config_stub.get(option)
@ -102,7 +102,7 @@ class TestSet:
with pytest.raises(cmdexc.CommandError,
match='Error while parsing :/: No scheme given'):
commands.set(0, option, 'false', url=':/')
commands.set(0, option, 'false', pattern=':/')
@pytest.mark.parametrize('temp', [True, False])
def test_set_temp_override(self, commands, config_stub, yaml_value, temp):