From 1306bd03c96bf8b36b68f19f86d656e24c959df6 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 22 Jun 2017 19:26:46 -0700 Subject: [PATCH] Support dumping json to stdout. Change-Id: I2e7243f1b9243ec98df54bd9f78b98cba8743217 Reviewed-on: https://chromium-review.googlesource.com/544792 Reviewed-by: Andrii Shyshkalov Reviewed-by: Aaron Gable Commit-Queue: Stefan Zager --- git_cl.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/git_cl.py b/git_cl.py index b80c7fc2a..58e5e8a9a 100755 --- a/git_cl.py +++ b/git_cl.py @@ -4402,8 +4402,11 @@ def colorize_CMDstatus_doc(): def write_json(path, contents): - with open(path, 'w') as f: - json.dump(contents, f) + if path == '-': + json.dump(contents, sys.stdout) + else: + with open(path, 'w') as f: + json.dump(contents, f) @subcommand.usage('[issue_number]') @@ -4416,7 +4419,8 @@ def CMDissue(parser, args): help='Lookup the branch(es) for the specified issues. If ' 'no issues are specified, all branches with mapped ' 'issues will be listed.') - parser.add_option('--json', help='Path to JSON output file.') + parser.add_option('--json', + help='Path to JSON output file, or "-" for stdout.') _add_codereview_select_options(parser) options, args = parser.parse_args(args) _process_codereview_select_options(parser, options) @@ -4473,7 +4477,7 @@ def CMDcomments(parser, args): help='output comments in a format compatible with ' 'editor parsing') parser.add_option('-j', '--json-file', - help='File to write JSON summary to') + help='File to write JSON summary to, or "-" for stdout') auth.add_auth_options(parser) _add_codereview_select_options(parser) options, args = parser.parse_args(args) @@ -5517,7 +5521,8 @@ def CMDtry_results(parser, args): '--buildbucket-host', default='cr-buildbucket.appspot.com', help='Host of buildbucket. The default host is %default.') group.add_option( - '--json', help='Path of JSON output file to write try job results to.') + '--json', help=('Path of JSON output file to write try job results to,' + 'or "-" for stdout.')) parser.add_option_group(group) auth.add_auth_options(parser) options, args = parser.parse_args(args)