From f7c0f8f11e442f92574a688254d40dc4d7227ca0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 15 Sep 2014 06:24:15 +0200 Subject: [PATCH] Remove :get and use :set with ...? instead. --- doc/help/commands.asciidoc | 15 +++----------- qutebrowser/config/config.py | 40 +++++++++++++----------------------- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index ec42906ed..32ebbc5ca 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -10,7 +10,6 @@ |<>|Cancel the first/[count]th download. |<>|Download the current page. |<>|Go forward in the history of the current tab. -|<>|Get the value from a section/option. |<>|Show help about a command or setting. |<>|Start hinting. |<>|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. diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 70109b493..2aac3ef63 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -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(