CLI support code seperated from main

Command line interface handling code was moved to its
own files.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: Ib547152af2dc5dcc2d595cf26dab65605ea2c32f
diff --git a/cli.cpp b/cli.cpp
new file mode 100644
index 0000000..4ace713
--- /dev/null
+++ b/cli.cpp
@@ -0,0 +1,86 @@
+#include <algorithm>
+#include <string>
+
+/** @brief Search the command line arguments for an option */
+bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
+{
+    return (i_end != std::find(i_begin, i_end, i_option));
+}
+
+/** @brief Search the command line arguments for a setting value */
+char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
+{
+    char** value = std::find(i_begin, i_end, i_setting);
+    return (value != i_end && ++value != i_end) ? *value : 0;
+}
+
+/** @brief Parse command line for configuration flags */
+void parseConfig(char** i_begin, char** i_end, bool& o_vital, bool& o_checkstop,
+                 bool& o_terminate, bool& o_breakpoints)
+{
+    char* setting;
+
+    // --all on/off takes precedence over individual settings
+    setting = getCliSetting(i_begin, i_end, "--all");
+    if (nullptr != setting)
+    {
+        if (std::string("off") == setting)
+        {
+            o_vital       = false;
+            o_checkstop   = false;
+            o_terminate   = false;
+            o_breakpoints = false;
+        }
+
+        if (std::string("on") == setting)
+        {
+            o_vital       = true;
+            o_checkstop   = true;
+            o_terminate   = true;
+            o_breakpoints = true;
+        }
+    }
+    // Parse individual options
+    else
+    {
+        setting = getCliSetting(i_begin, i_end, "--vital");
+        if (std::string("off") == setting)
+        {
+            o_vital = false;
+        }
+        if (std::string("on") == setting)
+        {
+            o_vital = true;
+        }
+
+        setting = getCliSetting(i_begin, i_end, "--checkstop");
+        if (std::string("off") == setting)
+        {
+            o_checkstop = false;
+        }
+        if (std::string("on") == setting)
+        {
+            o_checkstop = true;
+        }
+
+        setting = getCliSetting(i_begin, i_end, "--terminate");
+        if (std::string("off") == setting)
+        {
+            o_terminate = false;
+        }
+        if (std::string("on") == setting)
+        {
+            o_terminate = true;
+        }
+
+        setting = getCliSetting(i_begin, i_end, "--breakpoints");
+        if (std::string("off") == setting)
+        {
+            o_breakpoints = false;
+        }
+        if (std::string("on") == setting)
+        {
+            o_breakpoints = true;
+        }
+    }
+}
diff --git a/cli.hpp b/cli.hpp
new file mode 100644
index 0000000..f046b8c
--- /dev/null
+++ b/cli.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <string>
+
+/*
+ * @brief Search the command line arguments for an option
+ *
+ * @param i_begin   command line args vector begin
+ * @param i_end     command line args vector end
+ * @param i_option  configuration option to look for
+ *
+ * @return true = option found on command line
+ */
+bool getCliOption(char** i_begin, char** i_end, const std::string& i_option);
+
+/*
+ * @brief Search the command line arguments for a setting value
+ *
+ * @param i_begin   command line args vector begin
+ * @param i_end     command line args vectory end
+ * @param i_setting configuration setting to look for
+ *
+ * @return value of the setting or 0 if setting not found or value not given
+ */
+char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting);
+
+/*
+ *
+ * @brief Get configuration flags from command line
+ *
+ * @param i_begin       command line args vector begin
+ * @param i_end         command line args vector end
+ * @param i_vital       vital handler enable option
+ * @param i_checkatop   checkstop handler enable option
+ * @param i_terminate   TI handler enable option
+ * @param i_breakpoints breakpoint handler enable option
+ */
+void parseConfig(char** i_begin, char** i_end, bool& i_vital, bool& i_checkstop,
+                 bool& i_terminate, bool& i_breakpoints);
diff --git a/main.cpp b/main.cpp
index f36a3c0..bb43990 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,42 +2,7 @@
 
 #include <analyzer/analyzer_main.hpp>
 #include <attn/attn_main.hpp>
-
-#include <algorithm>
-#include <string>
-
-/*
- * @brief Search the command line arguments for an option
- *
- * @param i_begin   command line args vector begin
- * @param i_end     command line args vector end
- * @param i_option  configuration option to look for
- *
- * @return true = option found on command line
- */
-bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
-{
-    return (i_end != std::find(i_begin, i_end, i_option));
-}
-
-/*
- * @brief Search the command line arguments for a setting value
- *
- * @param i_begin   command line args vector begin
- * @param i_end     command line args vectory end
- * @param i_setting configuration setting to look for
- *
- * @return value of the setting or 0 if setting not found or value not given
- */
-char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
-{
-    char** value = std::find(i_begin, i_end, i_setting);
-    if (value != i_end && ++value != i_end)
-    {
-        return *value;
-    }
-    return 0; // nullptr
-}
+#include <cli.hpp>
 
 /**
  * @brief Attention handler application main()
diff --git a/meson.build b/meson.build
index e6d411f..9edebbf 100644
--- a/meson.build
+++ b/meson.build
@@ -15,7 +15,7 @@
 subdir('analyzer')
 subdir('attn')
 
-executable('openpower-hw-diags', 'main.cpp',
+executable('openpower-hw-diags', 'main.cpp', 'cli.cpp',
             link_with : [analyzer, attn],
             install : true)