Support dumping json to stdout.

Change-Id: I2e7243f1b9243ec98df54bd9f78b98cba8743217
Reviewed-on: https://chromium-review.googlesource.com/544792
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: Aaron Gable <agable@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index b80c7fc..58e5e8a 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -4402,8 +4402,11 @@
 
 
 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 @@
                     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 @@
                     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 @@
       '--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)