diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-03-05 17:35:41 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-03-05 17:35:41 +0100 |
commit | 748d57ee64036305a84301db7211b713c1995391 (patch) | |
tree | 1ecb834a0db215a1bbb784f3e8d45ad2ab80f183 /gitlab/cli.py | |
parent | c7b3f969fc3fcf9d057a23638d121f51513bb13c (diff) | |
download | gitlab-748d57ee64036305a84301db7211b713c1995391.tar.gz |
[cli] Allow to read args from files
With the @/file/path syntax (similar to curl) user can provide values
from attributes in files.
Fixes #448
Diffstat (limited to 'gitlab/cli.py')
-rw-r--r-- | gitlab/cli.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py index af82c09..36a1bda 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -114,6 +114,19 @@ def _get_parser(cli_module): return cli_module.extend_parser(parser) +def _parse_value(v): + if isinstance(v, str) and v.startswith('@'): + # If the user-provided value starts with @, we try to read the file + # path provided after @ as the real value. Exit on any error. + try: + return open(v[1:]).read() + except Exception as e: + sys.stderr.write("%s\n" % e) + sys.exit(1) + + return v + + def main(): if "--version" in sys.argv: print(gitlab.__version__) @@ -143,7 +156,7 @@ def main(): for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', 'action', 'version', 'output'): args.pop(item) - args = {k: v for k, v in args.items() if v is not None} + args = {k: _parse_value(v) for k, v in args.items() if v is not None} try: gl = gitlab.Gitlab.from_config(gitlab_id, config_files) |