sysd_monitor: Parse command line parameters
Tested:
- Verified multiple -f and --file options
- Verified -h and --help option
Change-Id: I0b528c7534df051685991576c040d0650faabf21
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/configure.ac b/configure.ac
index 7919ec5..07ef420 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,6 +17,13 @@
PKG_CHECK_MODULES([SDEVENTPLUS], [sdeventplus])
PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
+# We need the header only CLI library
+AC_CHECK_HEADERS(
+ [CLI/CLI.hpp],
+ [],
+ [AC_MSG_ERROR([Could not find CLI11 CLI/CLI.hpp])]
+)
+
# Checks for typedefs, structures, and compiler characteristics.
AX_CXX_COMPILE_STDCXX_17([noext])
AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
diff --git a/systemd_target_monitor.cpp b/systemd_target_monitor.cpp
index b9af29f..5fa05fa 100644
--- a/systemd_target_monitor.cpp
+++ b/systemd_target_monitor.cpp
@@ -1,13 +1,40 @@
+#include <CLI/CLI.hpp>
+#include <iostream>
+#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>
+#include <vector>
+
+using phosphor::logging::level;
+using phosphor::logging::log;
+
+void print_usage(void)
+{
+ std::cout << "[-f <file1> -f <file2> ...] : Full path to json file(s) with "
+ "target/error mappings"
+ << std::endl;
+ return;
+}
int main(int argc, char* argv[])
{
auto bus = sdbusplus::bus::new_default();
auto event = sdeventplus::Event::get_default();
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+ std::vector<std::string> filePaths;
- // TODO - Process input parameters
+ CLI::App app{"OpenBmc systemd target monitor"};
+ app.add_option("-f,--file", filePaths,
+ "Full path to json file(s) with target/error mappings");
+
+ CLI11_PARSE(app, argc, argv);
+
+ if (filePaths.empty())
+ {
+ log<level::ERR>("No input files");
+ print_usage();
+ exit(-1);
+ }
// TODO - Load in json config file(s)