argument parser: use CLI11 and add unit tests
CLI11 is one of the most commonly use argument parser in OpenBMC. It can
save ~150 lines of codes in this project.
We are hitting argument related bugs that not covered in unit tests.
This test adds a test for argument parsing.
Tested: QEMU IPMI/Redfish worked.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: Ib409c7e6a82ad31049f2da3e32727ebdf185f0fc
diff --git a/argument.hpp b/argument.hpp
index e67a877..5d0b558 100644
--- a/argument.hpp
+++ b/argument.hpp
@@ -1,39 +1,19 @@
#pragma once
-#include <getopt.h>
-
-#include <map>
#include <string>
-namespace phosphor::certs::util
+namespace phosphor::certs
{
-/**
- * @brief Class - Encapsulates parsing command line options and
- * populating arguments.
- */
-class ArgumentParser
+struct Arguments
{
- public:
- ArgumentParser(int argc, char** argv);
- ArgumentParser() = delete;
- ArgumentParser(const ArgumentParser&) = delete;
- ArgumentParser(ArgumentParser&&) = default;
- ArgumentParser& operator=(const ArgumentParser&) = delete;
- ArgumentParser& operator=(ArgumentParser&&) = default;
- ~ArgumentParser() = default;
- const std::string& operator[](const std::string& opt);
-
- static void usage(char** argv);
-
- static const std::string true_string;
- static const std::string empty_string;
-
- private:
- std::map<const std::string, std::string> arguments;
-
- static const option options[];
- static const char* optionstr;
+ std::string typeStr; // certificate type
+ std::string endpoint; // d-bus endpoint
+ std::string path; // certificate file path
+ std::string unit; // Optional systemd unit need to reload
};
-} // namespace phosphor::certs::util
+// Validates all |argv| is valid and set corresponding attributes in
+// |arguments|.
+int processArguments(int argc, const char* const* argv, Arguments& arguments);
+} // namespace phosphor::certs