sysd_monitor: Parse json file(s)

Parse the json file(s) into a c++ data object that can be used in later
commits to easily check for monitored targets and log appropriate
errors.

Accept a command line parameter to input file and call parsing function

Tested:
- Verified 100% code coverage of new parser cpp

Change-Id: I0bacd80b7f5330eb9cb03d8e3717742ab107bf94
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/systemd_target_monitor.cpp b/systemd_target_monitor.cpp
index 5fa05fa..2c58769 100644
--- a/systemd_target_monitor.cpp
+++ b/systemd_target_monitor.cpp
@@ -3,11 +3,30 @@
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/event.hpp>
+#include <systemd_target_parser.hpp>
 #include <vector>
 
 using phosphor::logging::level;
 using phosphor::logging::log;
 
+bool gVerbose = false;
+
+void dump_targets(const TargetErrorData& targetData)
+{
+    std::cout << "## Data Structure of Json ##" << std::endl;
+    for (const auto& [target, value] : targetData)
+    {
+        std::cout << target << " " << value.errorToLog << std::endl;
+        std::cout << "    ";
+        for (auto& eToMonitor : value.errorsToMonitor)
+        {
+            std::cout << eToMonitor << ", ";
+        }
+        std::cout << std::endl;
+    }
+    std::cout << std::endl;
+}
+
 void print_usage(void)
 {
     std::cout << "[-f <file1> -f <file2> ...] : Full path to json file(s) with "
@@ -26,6 +45,7 @@
     CLI::App app{"OpenBmc systemd target monitor"};
     app.add_option("-f,--file", filePaths,
                    "Full path to json file(s) with target/error mappings");
+    app.add_flag("-v", gVerbose, "Enable verbose output");
 
     CLI11_PARSE(app, argc, argv);
 
@@ -36,7 +56,19 @@
         exit(-1);
     }
 
-    // TODO - Load in json config file(s)
+    TargetErrorData targetData = parseFiles(filePaths);
+
+    if (targetData.size() == 0)
+    {
+        log<level::ERR>("Invalid input files, no targets found");
+        print_usage();
+        exit(-1);
+    }
+
+    if (gVerbose)
+    {
+        dump_targets(targetData);
+    }
 
     // TODO - Begin monitoring for systemd unit changes and logging appropriate
     //        errors