allow embedded hyphens in OptionHelper#getValidCliArgs CLI parsing

Bug: 30683145

Change-Id: Ifccebc1ef122114f3dd4465b0a66b277cfb14154
(cherry picked from commit 52464517276a4c6942e4c78d1fb6d5811faaf401)
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/CompatibilityTest.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/CompatibilityTest.java
index e75131f..ae3f271 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/CompatibilityTest.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/CompatibilityTest.java
@@ -172,7 +172,7 @@
 
     @Option(name = DEVICE_TOKEN_OPTION,
             description = "Holds the devices' tokens, used when scheduling tests that have"
-                    + "prerequisits such as requiring a SIM card. Format is <serial>:<token>",
+                    + "prerequisites such as requiring a SIM card. Format is <serial>:<token>",
             importance = Importance.ALWAYS)
     private List<String> mDeviceTokens = new ArrayList<>();
 
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/OptionHelper.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/OptionHelper.java
index 6eb1c95..1ca394a 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/OptionHelper.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/OptionHelper.java
@@ -103,11 +103,15 @@
         // get option/value substrings from the command-line string
         // N.B. tradefed rewrites some expressions from option="value a b" to "option=value a b"
         String quoteMatching = "(\"[^\"]+\")";
+        String nonSpacedHypen = "((?<!\\s)-(?!\\s))";
         Pattern cliPattern = Pattern.compile(
-            "((-[-\\w]+([ =]"                       // match -option=value or --option=value
-            + "(" + quoteMatching + "|[^-\"]+))?"   // allow -option "..." and -option x y z
+            // match -option=value or --option=value
+            "((-[-\\w]+([ =]"
+            // allow -option "...", -option x y z, and -option x:y:z
+            + "(" + quoteMatching + "|([\\w\\s:.]|"+ nonSpacedHypen + ")+))?"
             + "))|"
-            + quoteMatching                         // allow anything in direct quotes
+            // allow anything in direct quotes
+            + quoteMatching
         );
         Matcher matcher = cliPattern.matcher(commandString);
 
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/OptionHelperTest.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/OptionHelperTest.java
index c6f563f..d8cafa0 100644
--- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/OptionHelperTest.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/OptionHelperTest.java
@@ -77,7 +77,7 @@
         List<String> validSubset = Arrays.asList("--" + TEST_CLASS, "fooclass",
             "-" + TEST_SUITE_SHORTNAME, "foosuite");
         List<String> allValidNames = Arrays.asList("--" + TEST_CLASS, "fooclass",
-            "-" + TEST_SUITE_SHORTNAME, "foosuite", "--" + TEST_NAME, "footest");
+            "-" + TEST_SUITE_SHORTNAME, "foosuite:foo-key:fooval", "--" + TEST_NAME, "footest");
 
         List<String> validQuoteSubset = Arrays.asList("-" + TEST_CLASS_SHORTNAME, fakeTestClass,
             "--" + TEST_NAME + "=" + fakeTestMethod, "--" + TEST_FILTER, fakeTestClass + " "
@@ -94,7 +94,7 @@
                 + " -s foosuite", this));
         assertEquals("Expected two long names and one short name", allValidNames,
             OptionHelper.getValidCliArgs("test --" + TEST_CLASS + " fooclass -b fake"
-                + " -s foosuite " + "--" + TEST_NAME + " footest", this));
+                + " -s foosuite:foo-key:fooval " + "--" + TEST_NAME + " footest", this));
         assertEquals("Expected matching arrays", validQuoteSubset,
             OptionHelper.getValidCliArgs(inputString, this));
     }