commandline: promote "split_extend" as a common action

Move the custom "extend" action from cbuildbot into commandline as a
new common "split_extend" action.  This makes it work with argparse
and optparse so we can kill off more optparse-specific logic.

BUG=chromium:496565
TEST=precq passes

Change-Id: Ied2e754b7518d74481433740dd51bf2b303d5170
Reviewed-on: https://chromium-review.googlesource.com/612821
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index a82ea6f..6482ba2 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -341,12 +341,6 @@
 class CustomOption(commandline.FilteringOption):
   """Subclass FilteringOption class to implement pass-through and api."""
 
-  ACTIONS = commandline.FilteringOption.ACTIONS + ('extend',)
-  STORE_ACTIONS = commandline.FilteringOption.STORE_ACTIONS + ('extend',)
-  TYPED_ACTIONS = commandline.FilteringOption.TYPED_ACTIONS + ('extend',)
-  ALWAYS_TYPED_ACTIONS = (commandline.FilteringOption.ALWAYS_TYPED_ACTIONS +
-                          ('extend',))
-
   def __init__(self, *args, **kwargs):
     # The remote_pass_through argument specifies whether we should directly
     # pass the argument (with its value) onto the remote trybot.
@@ -354,19 +348,6 @@
     self.api_version = int(kwargs.pop('api', '0'))
     commandline.FilteringOption.__init__(self, *args, **kwargs)
 
-  def take_action(self, action, dest, opt, value, values, parser):
-    if action == 'extend':
-      # If there is extra spaces between each argument, we get '' which later
-      # code barfs on, so skip those.  e.g. We see this with the forms:
-      #  cbuildbot -p 'proj:branch ' ...
-      #  cbuildbot -p ' proj:branch' ...
-      #  cbuildbot -p 'proj:branch  proj2:branch' ...
-      lvalue = value.split()
-      values.ensure_value(dest, []).extend(lvalue)
-
-    commandline.FilteringOption.take_action(
-        self, action, dest, opt, value, values, parser)
-
 
 class CustomParser(commandline.FilteringParser):
   """Custom option parser which supports arguments passed-trhough to trybot"""
@@ -449,19 +430,19 @@
       parser,
       'Patch Options')
 
-  group.add_remote_option('-g', '--gerrit-patches', action='extend',
+  group.add_remote_option('-g', '--gerrit-patches', action='split_extend',
                           type='string', default=[],
                           metavar="'Id1 *int_Id2...IdN'",
                           help='Space-separated list of short-form Gerrit '
                                "Change-Id's or change numbers to patch. "
                                "Please prepend '*' to internal Change-Id's")
-  group.add_remote_option('-G', '--rietveld-patches', action='extend',
+  group.add_remote_option('-G', '--rietveld-patches', action='split_extend',
                           type='string', default=[],
                           metavar="'id1[:subdir1]...idN[:subdirN]'",
                           help='Space-separated list of short-form Rietveld '
                                'issue numbers to patch. If no subdir is '
                                'specified, the src directory is used.')
-  group.add_option('-p', '--local-patches', action='extend', default=[],
+  group.add_option('-p', '--local-patches', action='split_extend', default=[],
                    metavar="'<project1>[:<branch1>]...<projectN>[:<branchN>]'",
                    help='Space-separated list of project branches with '
                         'patches to apply.  Projects are specified by name. '
@@ -494,10 +475,10 @@
                    help='Attach an optional description to a --remote run '
                         'to make it easier to identify the results when it '
                         'finishes')
-  group.add_option('--slaves', action='extend', default=[],
+  group.add_option('--slaves', action='split_extend', default=[],
                    help='Specify specific remote tryslaves to run on (e.g. '
                         'build149-m2); if the bot is busy, it will be queued')
-  group.add_remote_option('--channel', action='extend', dest='channels',
+  group.add_remote_option('--channel', action='split_extend', dest='channels',
                           default=[],
                           help='Specify a channel for a payloads trybot. Can '
                                'be specified multiple times. No valid for '
@@ -700,7 +681,7 @@
   group.add_option('--buildbucket-id',
                    help='The unique ID in buildbucket of current build '
                         'generated by buildbucket.')
-  group.add_remote_option('--remote-patches', action='extend', default=[],
+  group.add_remote_option('--remote-patches', action='split_extend', default=[],
                           help='Patches uploaded by the trybot client when '
                                'run using the -p option')
   # Note the default here needs to be hardcoded to 3; that is the last version