gerrit: add a --raw option

Add an option for just extracting the gerrit CL numbers.
This way people can more easily script around the results.

BUG=chromium:384547
TEST=`gerrit --raw mine` only shows the CL numbers

Change-Id: Ieab89463f0d3709ac1fbf955c0a1b9f41f17705f
Reviewed-on: https://chromium-review.googlesource.com/203809
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/gerrit.py b/scripts/gerrit.py
index 1581d82..1402e54 100644
--- a/scripts/gerrit.py
+++ b/scripts/gerrit.py
@@ -93,6 +93,14 @@
 
 def PrintCl(opts, cls, lims, show_approvals=True):
   """Pretty print a single result"""
+  if opts.raw:
+    # Special case internal Chrome GoB as that is what most devs use.
+    # They can always redirect the list elsewhere via the -g option.
+    if opts.gob == constants.INTERNAL_GOB_INSTANCE:
+      print(constants.INTERNAL_CHANGE_PREFIX, end='')
+    print(cls['number'])
+    return
+
   if not lims:
     lims = {'url': 0, 'project': 0}
 
@@ -319,6 +327,8 @@
                            (constants.EXTERNAL_GOB_INSTANCE))
   parser.add_argument('--sort', default='number',
                       help='Key to sort on (number, project)')
+  parser.add_argument('--raw', default=False, action='store_true',
+                      help='Return raw results (suitable for scripting)')
   parser.add_argument('-v', '--verbose', default=False, action='store_true',
                       help='Be more verbose in output')
   parser.add_argument('args', nargs='+')