diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2017-08-18 10:25:00 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2017-08-18 10:34:05 +0200 |
commit | abade405af9099a136b68d0eb19027d038dab60b (patch) | |
tree | 8f2877a69f5e0134ed7f39c899909d0f79e6325b /gitlab/cli.py | |
parent | 9783207f4577bd572f09c25707981ed5aa83b116 (diff) | |
download | gitlab-abade405af9099a136b68d0eb19027d038dab60b.tar.gz |
CLI: yaml and json outputs for v4
Verbose mode only works with the legacy output. Also add support for
filtering the output by defining the list of fields that need to be
displayed (yaml and json only).
Diffstat (limited to 'gitlab/cli.py')
-rw-r--r-- | gitlab/cli.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py index d803eb5..f6b357b 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -51,7 +51,6 @@ def register_custom_action(cls_name, mandatory=tuple(), optional=tuple()): custom_actions[final_name] = {} action = f.__name__ - custom_actions[final_name][action] = (mandatory, optional, in_obj) return wrapped_f @@ -79,7 +78,7 @@ def _get_base_parser(): parser.add_argument("--version", help="Display the version.", action="store_true") parser.add_argument("-v", "--verbose", "--fancy", - help="Verbose mode", + help="Verbose mode (legacy format only)", action="store_true") parser.add_argument("-d", "--debug", help="Debug mode (display HTTP requests", @@ -92,6 +91,15 @@ def _get_base_parser(): "be used. If not defined, the default selection " "will be used."), required=False) + parser.add_argument("-o", "--output", + help=("Output format (v4 only): json|legacy|yaml"), + required=False, + choices=['json', 'legacy', 'yaml'], + default="legacy") + parser.add_argument("-f", "--fields", + help=("Fields to display in the output (comma " + "separated). Not used with legacy output"), + required=False) return parser @@ -117,6 +125,10 @@ def main(): config_files = args.config_file gitlab_id = args.gitlab verbose = args.verbose + output = args.output + fields = [] + if args.fields: + fields = [x.strip() for x in args.fields.split(',')] debug = args.debug action = args.action what = args.what @@ -124,7 +136,7 @@ def main(): args = args.__dict__ # Remove CLI behavior-related args for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', 'action', - 'version'): + 'version', 'output'): args.pop(item) args = {k: v for k, v in args.items() if v is not None} @@ -137,6 +149,6 @@ def main(): if debug: gl.enable_debug() - cli_module.run(gl, what, action, args, verbose) + cli_module.run(gl, what, action, args, verbose, output, fields) sys.exit(0) |