Add -p/--print argument to :set to print value.
This commit is contained in:
parent
7615e20091
commit
f78b21874f
@ -510,7 +510,8 @@ class ConfigManager(QObject):
|
|||||||
Completion.value])
|
Completion.value])
|
||||||
def set_command(self, win_id: {'special': 'win_id'},
|
def set_command(self, win_id: {'special': 'win_id'},
|
||||||
sectname: {'name': 'section'}=None,
|
sectname: {'name': 'section'}=None,
|
||||||
optname: {'name': 'option'}=None, value=None, temp=False):
|
optname: {'name': 'option'}=None, value=None, temp=False,
|
||||||
|
print_val: {'name': 'print'}=False):
|
||||||
"""Set an option.
|
"""Set an option.
|
||||||
|
|
||||||
If the option name ends with '?', the value of the option is shown
|
If the option name ends with '?', the value of the option is shown
|
||||||
@ -527,6 +528,7 @@ class ConfigManager(QObject):
|
|||||||
optname: The name of the option.
|
optname: The name of the option.
|
||||||
value: The value to set.
|
value: The value to set.
|
||||||
temp: Set value temporarily.
|
temp: Set value temporarily.
|
||||||
|
print_val: Print the value after setting.
|
||||||
"""
|
"""
|
||||||
if sectname is not None and optname is None:
|
if sectname is not None and optname is None:
|
||||||
raise cmdexc.CommandError(
|
raise cmdexc.CommandError(
|
||||||
@ -537,28 +539,34 @@ class ConfigManager(QObject):
|
|||||||
window=win_id)
|
window=win_id)
|
||||||
tabbed_browser.openurl(QUrl('qute:settings'), newtab=False)
|
tabbed_browser.openurl(QUrl('qute:settings'), newtab=False)
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
if optname.endswith('?'):
|
if optname.endswith('?'):
|
||||||
val = self.get(sectname, optname[:-1], transformed=False)
|
optname = optname[:-1]
|
||||||
message.info(win_id, "{} {} = {}".format(
|
print_val = True
|
||||||
sectname, optname[:-1], val), immediately=True)
|
else:
|
||||||
elif optname.endswith('!'):
|
try:
|
||||||
val = self.get(sectname, optname[:-1])
|
if optname.endswith('!'):
|
||||||
layer = 'temp' if temp else 'conf'
|
val = self.get(sectname, optname[:-1])
|
||||||
if isinstance(val, bool):
|
layer = 'temp' if temp else 'conf'
|
||||||
self.set(layer, sectname, optname[:-1], str(not val))
|
if isinstance(val, bool):
|
||||||
|
self.set(layer, sectname, optname[:-1], str(not val))
|
||||||
|
else:
|
||||||
|
raise cmdexc.CommandError(
|
||||||
|
"set: Attempted inversion of non-boolean value.")
|
||||||
else:
|
else:
|
||||||
raise cmdexc.CommandError("set: Attempted inversion of "
|
if value is None:
|
||||||
"non-boolean value.")
|
raise cmdexc.CommandError(
|
||||||
else:
|
"set: The following arguments are required: value")
|
||||||
if value is None:
|
layer = 'temp' if temp else 'conf'
|
||||||
raise cmdexc.CommandError("set: The following arguments "
|
self.set(layer, sectname, optname, value)
|
||||||
"are required: value")
|
except (configexc.Error, configparser.Error) as e:
|
||||||
layer = 'temp' if temp else 'conf'
|
raise cmdexc.CommandError("set: {} - {}".format(
|
||||||
self.set(layer, sectname, optname, value)
|
e.__class__.__name__, e))
|
||||||
except (configexc.Error, configparser.Error) as e:
|
|
||||||
raise cmdexc.CommandError("set: {} - {}".format(
|
if print_val:
|
||||||
e.__class__.__name__, e))
|
val = self.get(sectname, optname, transformed=False)
|
||||||
|
message.info(win_id, "{} {} = {}".format(
|
||||||
|
sectname, optname, val), immediately=True)
|
||||||
|
|
||||||
def set(self, layer, sectname, optname, value, validate=True):
|
def set(self, layer, sectname, optname, value, validate=True):
|
||||||
"""Set an option.
|
"""Set an option.
|
||||||
|
Loading…
Reference in New Issue
Block a user