Remove :get and use :set with ...? instead.

This commit is contained in:
Florian Bruhin 2014-09-15 06:24:15 +02:00
parent 22e6a26ec3
commit f7c0f8f11e
2 changed files with 17 additions and 38 deletions

View File

@ -10,7 +10,6 @@
|<<cancel-download,cancel-download>>|Cancel the first/[count]th download.
|<<download-page,download-page>>|Download the current page.
|<<forward,forward>>|Go forward in the history of the current tab.
|<<get,get>>|Get the value from a section/option.
|<<help,help>>|Show help about a command or setting.
|<<hint,hint>>|Start hinting.
|<<home,home>>|Open main startpage in current tab.
@ -86,16 +85,6 @@ Go forward in the history of the current tab.
==== count
How many pages to go forward.
[[get]]
=== get
Syntax: +:get 'section' 'option'+
Get the value from a section/option.
==== positional arguments
* +'section'+: The section where the option is in.
* +'option'+: The name of the option.
[[help]]
=== help
Syntax: +:help ['topic']+
@ -293,10 +282,12 @@ Save the config file.
[[set]]
=== set
Syntax: +:set [*--temp*] 'section' 'option' 'value'+
Syntax: +:set [*--temp*] 'section' 'option' ['value']+
Set an option.
If the option name ends with '?', the value of the option is shown instead.
==== positional arguments
* +'section'+: The section where the option is in.
* +'option'+: The name of the option.

View File

@ -281,29 +281,6 @@ class ConfigManager(QObject):
self.get.cache_clear()
return existed
@cmdutils.register(name='get', instance='config',
completion=[Completion.section, Completion.option])
def get_command(self, sectname: {'name': 'section'},
optname: {'name': 'option'}):
"""Get the value from a section/option.
//
Wrapper for the get-command to output the value in the status bar.
Args:
sectname: The section where the option is in.
optname: The name of the option.
"""
try:
val = self.get(sectname, optname, transformed=False)
except (NoOptionError, NoSectionError) as e:
raise cmdexc.CommandError("get: {} - {}".format(
e.__class__.__name__, e))
else:
message.info("{} {} = {}".format(sectname, optname, val),
immediately=True)
@functools.lru_cache()
def get(self, sectname, optname, raw=False, transformed=True):
"""Get the value from a section/option.
@ -338,9 +315,12 @@ class ConfigManager(QObject):
completion=[Completion.section, Completion.option,
Completion.value])
def set_command(self, sectname: {'name': 'section'},
optname: {'name': 'option'}, value, temp=False):
optname: {'name': 'option'}, value=None, temp=False):
"""Set an option.
If the option name ends with '?', the value of the option is shown
instead.
//
Wrapper for self.set() to output exceptions in the status bar.
@ -352,8 +332,16 @@ class ConfigManager(QObject):
temp: Set value temporarily.
"""
try:
layer = 'temp' if temp else 'conf'
self.set(layer, sectname, optname, value)
if optname.endswith('?'):
val = self.get(sectname, optname[:-1], transformed=False)
message.info("{} {} = {}".format(sectname, optname[:-1], val),
immediately=True)
else:
if value is None:
raise cmdexc.CommandError("set: The following arguments "
"are required: value")
layer = 'temp' if temp else 'conf'
self.set(layer, sectname, optname, value)
except (NoOptionError, NoSectionError, configtypes.ValidationError,
ValueError) as e:
raise cmdexc.CommandError("set: {} - {}".format(