summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2019-03-11 09:11:55 -0700
committerPatrick Venture <venture@google.com>2019-03-11 09:27:39 -0700
commitb5cc37cebec74f0bd2a8d378d5f911fc4fa3439e (patch)
tree8bec45837654acfe7df5192c3c0c659616e59d79
parent6d31049a4eb38f7b86874e9286c771ae0dd5f14d (diff)
downloadphosphor-pid-control-b5cc37cebec74f0bd2a8d378d5f911fc4fa3439e.tar.gz
phosphor-pid-control-b5cc37cebec74f0bd2a8d378d5f911fc4fa3439e.zip
swap out getopts for cli11
Swap out getopt for cli11 for parsing parameters. Change-Id: If6845c359dafc28b545925faa4701d401c7b8dd2 Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--configure.ac6
-rw-r--r--main.cpp49
2 files changed, 21 insertions, 34 deletions
diff --git a/configure.ac b/configure.ac
index b7f743f..d766ba8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,6 +50,12 @@ AC_CHECK_HEADER(
[],
[AC_MSG_ERROR([Could not find nlohmann/json.hpp])]
)
+# We need the header only CLI library
+AC_CHECK_HEADERS(
+ [CLI/CLI.hpp],
+ [],
+ [AC_MSG_ERROR([Could not find CLI11 CLI/CLI.hpp])]
+)
AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
# Checks for library functions.
diff --git a/main.cpp b/main.cpp
index cec3789..2db1ff9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -30,8 +30,7 @@
#include "threads/busthread.hpp"
#include "util.hpp"
-#include <getopt.h>
-
+#include <CLI/CLI.hpp>
#include <chrono>
#include <iostream>
#include <map>
@@ -60,39 +59,21 @@ int main(int argc, char* argv[])
{
int rc = 0;
std::string configPath = "";
+ tuningLoggingPath = "";
- while (1)
- {
- // clang-format off
- static struct option long_options[] = {
- {"conf", required_argument, 0, 'c'},
- {"tuning", required_argument, 0, 't'},
- {0, 0, 0, 0}
- };
- // clang-format on
-
- int option_index = 0;
- int c = getopt_long(argc, argv, "t:c:", long_options, &option_index);
-
- if (c == -1)
- {
- break;
- }
-
- switch (c)
- {
- case 'c':
- configPath = std::string{optarg};
- break;
- case 't':
- tuningLoggingEnabled = true;
- tuningLoggingPath = std::string{optarg};
- break;
- default:
- /* skip garbage. */
- continue;
- }
- }
+ CLI::App app{"OpenBMC Fan Control Daemon"};
+
+ app.add_option("-c,--conf", configPath,
+ "Optional parameter to specify configuration at run-time")
+ ->check(CLI::ExistingFile);
+ app.add_option("-t,--tuning", tuningLoggingPath,
+ "Optional parameter to specify tuning logging path, and "
+ "enable tuning")
+ ->check(CLI::ExistingFile);
+
+ CLI11_PARSE(app, argc, argv);
+
+ tuningLoggingEnabled = (tuningLoggingPath.length() > 0);
auto modeControlBus = sdbusplus::bus::new_system();
static constexpr auto modeRoot = "/xyz/openbmc_project/settings/fanctrl";
OpenPOWER on IntegriCloud