argument: Reset optind before using getopt

The getopt family of functions are globally stateful, we need to make
sure that we reset the global state before using it otherwise we can't
create arguments more than once.

Change-Id: Ic673eb3592217329b95fde033a1f2773b6b980bf
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/argument.cpp b/argument.cpp
index 41ea9ae..61c97ca 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -42,6 +42,13 @@
 ArgumentParser::ArgumentParser(int argc, char** argv)
 {
     int option = 0;
+
+    // We have to reset optind because getopt_long keeps global state
+    // and uses optind to track what argv index it needs to process next.
+    // Since this object may be instantiated more than once or test suites may
+    // already process instructions, optind may not be initialized to point to
+    // the beginning of our argv.
+    optind = 0;
     while (-1 != (option = getopt_long(argc, argv, optionStr, options, nullptr)))
     {
         if ((option == '?') || (option == 'h'))