From 780c919d88864790445cfd38921c11d50ecf58c4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 3 Aug 2014 22:04:09 +0400 Subject: [PATCH 1/2] Add documentation for `powerline --help` --- powerline/shell.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/powerline/shell.py b/powerline/shell.py index 8cfb2de6..8ab81ae8 100644 --- a/powerline/shell.py +++ b/powerline/shell.py @@ -52,17 +52,18 @@ def get_argparser(parser=None, *args, **kwargs): import argparse parser = argparse.ArgumentParser p = parser(*args, **kwargs) - p.add_argument('ext', nargs=1) - p.add_argument('side', nargs='?', choices=('left', 'right', 'above', 'aboveleft')) - p.add_argument('-r', '--renderer_module', metavar='MODULE', type=str) - p.add_argument('-w', '--width', type=int) - p.add_argument('--last_exit_code', metavar='INT', type=int) - p.add_argument('--last_pipe_status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()]) - p.add_argument('--jobnum', metavar='INT', type=int) - p.add_argument('-c', '--config', metavar='KEY.KEY=VALUE', action='append') - p.add_argument('-t', '--theme_option', metavar='THEME.KEY.KEY=VALUE', action='append') - p.add_argument('-p', '--config_path', metavar='PATH') - p.add_argument('-R', '--renderer_arg', metavar='KEY=VAL', action='append') + p.add_argument('ext', nargs=1, help='Extension: application for which powerline command is launched (usually `shell\' or `tmux\')') + p.add_argument('side', nargs='?', choices=('left', 'right', 'above', 'aboveleft'), help='Side: `left\' and `right\' represent left and right side respectively, `above\' emits lines that are supposed to be printed just above the prompt and `aboveleft\' is like concatenating `above\' with `left\' with the exception that only one Python instance is used in this case.') + p.add_argument('-r', '--renderer_module', metavar='MODULE', type=str, + help='Renderer module. Usually something like `bash_prompt\' or `zsh_prompt\', is supposed to be set only in shell-specific bindings file.') + p.add_argument('-w', '--width', type=int, help='Maximum prompt with. Triggers truncation of some segments') + p.add_argument('--last_exit_code', metavar='INT', type=int, help='Last exit code') + p.add_argument('--last_pipe_status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()], help='Like above, but is supposed to contain space-separated array of statuses, representing exit statuses of commands in one pipe.') + p.add_argument('--jobnum', metavar='INT', type=int, help='Number of jobs.') + p.add_argument('-c', '--config', metavar='KEY.KEY=VALUE', action='append', help='Configuration overrides for `config.json\'. Is translated to a dictionary and merged with the dictionary obtained from actual JSON configuration: KEY.KEY=VALUE is translated to `{"KEY": {"KEY": VALUE}}\' and then merged recursively. VALUE may be any JSON value, values that are not `null\', `true\', `false\', start with digit, `{\', `[\' are treated like strings. If VALUE is omitted then corresponding key is removed.') + p.add_argument('-t', '--theme_option', metavar='THEME.KEY.KEY=VALUE', action='append', help='Like above, but theme-specific. THEME should point to an existing and used theme to have any effect, but it is fine to use any theme here.') + p.add_argument('-R', '--renderer_arg', metavar='KEY=VAL', action='append', help='Like above, but provides argument for renderer. Is supposed to be used only by shell bindings to provide various data like last_exit_code or last_pipe_status (they are not using --renderer_arg for historical resons: renderer_arg was added later).') + p.add_argument('-p', '--config_path', metavar='PATH', help='Path to configuration directory. If it is present then configuration files will only be seeked in the provided path.') return p From 3d1f9bfbbd8d20231ff4a106efa8bde458cf3b17 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 3 Aug 2014 22:20:01 +0400 Subject: [PATCH 2/2] Allow multiple arguments to `powerline[-lint] --config_path` --- powerline/lint/__init__.py | 4 ++-- powerline/shell.py | 7 ++----- scripts/powerline-lint | 2 +- tests/test_cmdline.py | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/powerline/lint/__init__.py b/powerline/lint/__init__.py index 9b3661e7..ffe58420 100644 --- a/powerline/lint/__init__.py +++ b/powerline/lint/__init__.py @@ -1133,8 +1133,8 @@ theme_spec = (Spec( ).context_message('Error while loading theme')) -def check(path=None, debug=False): - search_paths = [path] if path else get_config_paths() +def check(paths=None, debug=False): + search_paths = paths or get_config_paths() find_config_file = generate_config_finder(lambda: search_paths) logger = logging.getLogger('powerline-lint') diff --git a/powerline/shell.py b/powerline/shell.py index 8ab81ae8..baf0973c 100644 --- a/powerline/shell.py +++ b/powerline/shell.py @@ -34,10 +34,7 @@ class ShellPowerline(Powerline): return r def get_config_paths(self): - if self.args.config_path: - return [self.args.config_path] - else: - return super(ShellPowerline, self).get_config_paths() + return self.args.config_path or super(ShellPowerline, self).get_config_paths() def get_local_themes(self, local_themes): if not local_themes: @@ -63,7 +60,7 @@ def get_argparser(parser=None, *args, **kwargs): p.add_argument('-c', '--config', metavar='KEY.KEY=VALUE', action='append', help='Configuration overrides for `config.json\'. Is translated to a dictionary and merged with the dictionary obtained from actual JSON configuration: KEY.KEY=VALUE is translated to `{"KEY": {"KEY": VALUE}}\' and then merged recursively. VALUE may be any JSON value, values that are not `null\', `true\', `false\', start with digit, `{\', `[\' are treated like strings. If VALUE is omitted then corresponding key is removed.') p.add_argument('-t', '--theme_option', metavar='THEME.KEY.KEY=VALUE', action='append', help='Like above, but theme-specific. THEME should point to an existing and used theme to have any effect, but it is fine to use any theme here.') p.add_argument('-R', '--renderer_arg', metavar='KEY=VAL', action='append', help='Like above, but provides argument for renderer. Is supposed to be used only by shell bindings to provide various data like last_exit_code or last_pipe_status (they are not using --renderer_arg for historical resons: renderer_arg was added later).') - p.add_argument('-p', '--config_path', metavar='PATH', help='Path to configuration directory. If it is present then configuration files will only be seeked in the provided path.') + p.add_argument('-p', '--config_path', action='append', metavar='PATH', help='Path to configuration directory. If it is present then configuration files will only be seeked in the provided path. May be provided multiple times to search in a list of directories.') return p diff --git a/scripts/powerline-lint b/scripts/powerline-lint index d8a05ca3..5a9b1285 100755 --- a/scripts/powerline-lint +++ b/scripts/powerline-lint @@ -7,7 +7,7 @@ import sys parser = argparse.ArgumentParser(description=__doc__) -parser.add_argument('-p', '--config_path', metavar='PATH') +parser.add_argument('-p', '--config_path', action='append', metavar='PATH') parser.add_argument('-d', '--debug', action='store_const', const=True) if __name__ == '__main__': diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 91f27adb..9895709f 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -90,7 +90,7 @@ class TestParser(TestCase): } } }, - 'config_path': '.', + 'config_path': ['.'], 'renderer_arg': {'smth': {'abc': 'def'}}, }), (['shell', '-R', 'arg=true'], {'ext': ['shell'], 'renderer_arg': {'arg': True}}),