Populate ALL copies of a command line flag during parsing

Now that we're declaring flags statically per-tool, we were only
setting the value on one of them (randomly) in the linked list.

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3881

Change-Id: I448cb7f42ee01a16daa65986b14aee9f1a2a3588
Reviewed-on: https://skia-review.googlesource.com/3881
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index fd7c8ff..bbbc397 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -288,11 +288,18 @@
             helpPrinted = true;
         }
         if (!helpPrinted) {
-            bool flagMatched = false;
+            SkFlagInfo* matchedFlag = nullptr;
             SkFlagInfo* flag = gHead;
+            int startI = i;
             while (flag != nullptr) {
-                if (flag->match(argv[i])) {
-                    flagMatched = true;
+                if (flag->match(argv[startI])) {
+                    i = startI;
+                    if (matchedFlag) {
+                        // Don't redefine the same flag with different types.
+                        SkASSERT(matchedFlag->getFlagType() == flag->getFlagType());
+                    } else {
+                        matchedFlag = flag;
+                    }
                     switch (flag->getFlagType()) {
                         case SkFlagInfo::kBool_FlagType:
                             // Can be handled by match, above, but can also be set by the next
@@ -330,11 +337,10 @@
                         default:
                             SkDEBUGFAIL("Invalid flag type");
                     }
-                    break;
                 }
                 flag = flag->next();
             }
-            if (!flagMatched) {
+            if (!matchedFlag) {
 #if defined(SK_BUILD_FOR_MAC)
                 if (SkStrStartsWith(argv[i], "NSDocumentRevisions")
                         || SkStrStartsWith(argv[i], "-NSDocumentRevisions")) {