diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 4ea0e6b3..51a20595 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -472,11 +472,17 @@ Powerline script has a number of options controlling powerline behavior. Here example: ``{"K1": V1, "K2": V2}``) is recursively merged with the contents of the file. + If ``VALUE`` is omitted then corresponding key will be removed from the + configuration (if it was present). + ``-t THEME_NAME.KEY.NESTED_KEY=VALUE`` or ``--theme_option=THEME_NAME.KEY.NESTED_KEY=VALUE`` Overrides options from :file:`powerline/themes/{ext}/{THEME_NAME}.json`. ``KEY.NESTED_KEY=VALUE`` is processed like described above, ``{ext}`` is the first argument to powerline script. May be passed multiple times. + If ``VALUE`` is omitted then corresponding key will be removed from the + configuration (if it was present). + ``-p PATH`` or ``--config_path=PATH`` Sets directory where configuration should be read from. If present, no default locations are searched for configuration. No expansions are diff --git a/powerline/lib/__init__.py b/powerline/lib/__init__.py index f8d831ac..b68b4830 100644 --- a/powerline/lib/__init__.py +++ b/powerline/lib/__init__.py @@ -3,6 +3,9 @@ from functools import wraps import json +REMOVE_THIS_KEY = object() + + def wraps_saveargs(wrapped): def dec(wrapper): r = wraps(wrapped)(wrapper) @@ -17,6 +20,8 @@ def mergedicts(d1, d2): for k in d2: if k in d1 and type(d1[k]) is dict and type(d2[k]) is dict: mergedicts(d1[k], d2[k]) + elif d2[k] is REMOVE_THIS_KEY: + d1.pop(k, None) else: d1[k] = d2[k] @@ -45,7 +50,9 @@ def keyvaluesplit(s): idx = s.index('=') o = s[:idx] rest = s[idx + 1:] - if rest[0] in '"{[0193456789' or rest in ('null', 'true', 'false'): + if not rest: + val = REMOVE_THIS_KEY + elif rest[0] in '"{[0193456789' or rest in ('null', 'true', 'false'): val = json.loads(s[idx + 1:]) else: val = rest diff --git a/powerline/shell.py b/powerline/shell.py index 677f2c49..4b817ae1 100644 --- a/powerline/shell.py +++ b/powerline/shell.py @@ -7,8 +7,7 @@ from powerline.lib import mergedicts, parsedotval def mergeargs(argvalue): if not argvalue: return None - argvalue = iter(argvalue) - r = dict([next(argvalue)]) + r = {} for subval in argvalue: mergedicts(r, dict([subval])) return r diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index c330da36..91f27adb 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -94,6 +94,8 @@ class TestParser(TestCase): 'renderer_arg': {'smth': {'abc': 'def'}}, }), (['shell', '-R', 'arg=true'], {'ext': ['shell'], 'renderer_arg': {'arg': True}}), + (['shell', '-R', 'arg=true', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}}), + (['shell', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}}), (['shell', '-t', 'default.segment_info={"hostname": {}}'], { 'ext': ['shell'], 'theme_option': { diff --git a/tests/test_lib.py b/tests/test_lib.py index f4da57d2..6c306615 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -1,7 +1,7 @@ # vim:fileencoding=utf-8:noet from __future__ import division -from powerline.lib import mergedicts, add_divider_highlight_group +from powerline.lib import mergedicts, add_divider_highlight_group, REMOVE_THIS_KEY from powerline.lib.humanize_bytes import humanize_bytes from powerline.lib.vcs import guess from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment @@ -354,6 +354,8 @@ class TestLib(TestCase): self.assertEqual(d, {'abc': {'def': {'ghi': 'jkl'}}}) mergedicts(d, {'abc': {'mno': 'pqr'}}) self.assertEqual(d, {'abc': {'def': {'ghi': 'jkl'}, 'mno': 'pqr'}}) + mergedicts(d, {'abc': {'def': REMOVE_THIS_KEY}}) + self.assertEqual(d, {'abc': {'mno': 'pqr'}}) def test_add_divider_highlight_group(self): def decorated_function_name(**kwargs):