Convert to standard CLI11 argument parser

This simplifies the argument parsing logic drastically and still
provides the same error handling as before.

Tested:
    Ran through unit test suite and manually verified that the command
    line functions as expected on a real BMC.

Change-Id: Ic5d69adf5359f9f64f2ada17e6a8f3242ca03e25
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 1c44162..bb1d048 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,8 +4,7 @@
 TESTS = $(check_PROGRAMS)
 
 # Build/add utest to test suite
-check_PROGRAMS = argument_test \
-                 watchdog_test
+check_PROGRAMS = watchdog_test
 
 utestCPPFLAGS = $(GTEST_MAIN_CFLAGS) \
                 $(AM_CPPFLAGS) \
@@ -24,13 +23,8 @@
                $(PHOSPHOR_LOGGING_LIBS) \
                $(PHOSPHOR_DBUS_INTERFACES_LIBS)
 
-argument_test_CPPFLAGS = ${utestCPPFLAGS}
-argument_test_CXXFLAGS = ${utestCXXFLAGS}
-argument_test_LDFLAGS = ${utestLDFLAGS}
-
 watchdog_test_CPPFLAGS = ${utestCPPFLAGS}
 watchdog_test_CXXFLAGS = ${utestCXXFLAGS}
 watchdog_test_LDFLAGS = ${utestLDFLAGS}
 
-argument_test_SOURCES = ../argument.cpp argument_test.cpp
 watchdog_test_SOURCES = ../watchdog.cpp watchdog_test.cpp
diff --git a/test/argument_test.cpp b/test/argument_test.cpp
deleted file mode 100644
index 3cb5dc9..0000000
--- a/test/argument_test.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-#include "argument_test.hpp"
-
-#include "argument.hpp"
-
-#include <string>
-#include <vector>
-
-static const std::string expected_path1 = "/arg1-test-path";
-static const std::string expected_target1 = "t1.target";
-static const std::string expected_target2 = "t2.target";
-
-// Allow for a single unrecognized option then the Usage printout
-static const std::string invalid_arg_regex =
-    "^[^\n]*unrecognized option[^\n]*\nUsage: ";
-
-static const std::string clean_usage_regex = "^Usage: ";
-
-namespace phosphor
-{
-namespace watchdog
-{
-
-void ArgumentTest::SetUp()
-{
-    arg0 = "argument_test";
-}
-
-/** @brief ArgumentParser should return no values if given no options */
-TEST_F(ArgumentTest, NoOptions)
-{
-    char* const args[] = {&arg0[0], nullptr};
-    ArgumentParser ap(sizeof(args) / sizeof(char*) - 1, args);
-    EXPECT_EQ(std::vector<std::string>({}), ap["path"]);
-    EXPECT_EQ(std::vector<std::string>({}), ap["continue"]);
-    EXPECT_EQ(std::vector<std::string>({}), ap["arbitrary_unknown"]);
-}
-
-/** @brief ArgumentParser should return true for an existing no-arg option
- *         Make sure we don't parse arguments if an option takes none
- *         Also make sure we don't populate options not used.
- */
-TEST_F(ArgumentTest, LongOptionNoArg)
-{
-    std::string arg_continue = "--continue";
-    std::string arg_extra = "not-a-bool";
-    char* const args[] = {&arg0[0], &arg_continue[0], &arg_extra[0], nullptr};
-    ArgumentParser ap(sizeof(args) / sizeof(char*) - 1, args);
-    EXPECT_EQ(std::vector<std::string>({}), ap["path"]);
-    EXPECT_EQ(std::vector<std::string>({ArgumentParser::trueString}),
-              ap["continue"]);
-}
-
-/** @brief ArgumentParser should return a string for long options that
- *         take an arg
- */
-TEST_F(ArgumentTest, LongOptionRequiredArg)
-{
-    std::string arg_path = "--path";
-    std::string arg_path_val = expected_path1;
-    std::string arg_extra = "/unused-path";
-    char* const args[] = {&arg0[0], &arg_path[0], &arg_path_val[0],
-                          &arg_extra[0], nullptr};
-    ArgumentParser ap(sizeof(args) / sizeof(char*) - 1, args);
-    EXPECT_EQ(std::vector<std::string>({expected_path1}), ap["path"]);
-}
-
-/** @brief ArgumentParser should return a string for long options that
- *         accept an argument when passed an argument inline
- */
-TEST_F(ArgumentTest, LongOptionInlineArg)
-{
-    std::string arg_path = "--path=" + expected_path1;
-    std::string arg_extra = "/unused-path";
-    char* const args[] = {&arg0[0], &arg_path[0], &arg_extra[0], nullptr};
-    ArgumentParser ap(sizeof(args) / sizeof(char*) - 1, args);
-    EXPECT_EQ(std::vector<std::string>({expected_path1}), ap["path"]);
-}
-
-/** @brief ArgumentParser should return a string for short options that
- *         accept an argument.
- */
-TEST_F(ArgumentTest, ShortOptionRequiredArg)
-{
-    std::string arg_path = "-p";
-    std::string arg_path_val = expected_path1;
-    std::string arg_extra = "/unused-path";
-    char* const args[] = {&arg0[0], &arg_path[0], &arg_path_val[0],
-                          &arg_extra[0], nullptr};
-    ArgumentParser ap(sizeof(args) / sizeof(char*) - 1, args);
-    EXPECT_EQ(std::vector<std::string>({expected_path1}), ap["path"]);
-}
-
-/** @brief ArgumentParser should be able to handle parsing multiple options
- *         Make sure this works for no-arg and required-arg type options
- *         Make sure this works between short and long options
- */
-TEST_F(ArgumentTest, MultiOptionOverride)
-{
-    std::string arg_continue_short = "-c";
-    std::string arg_path = "--path=" + expected_path1;
-    std::string arg_continue_long = "--continue";
-    std::string arg_target = "--target=" + expected_target2;
-    std::string arg_target_short = "-t";
-    std::string arg_target_val = expected_target1;
-    char* const args[] = {&arg0[0],           &arg_continue_short[0],
-                          &arg_path[0],       &arg_continue_long[0],
-                          &arg_target[0],     &arg_target_short[0],
-                          &arg_target_val[0], nullptr};
-    ArgumentParser ap(sizeof(args) / sizeof(char*) - 1, args);
-    EXPECT_EQ(std::vector<std::string>({expected_path1}), ap["path"]);
-    EXPECT_EQ(std::vector<std::string>(
-                  {ArgumentParser::trueString, ArgumentParser::trueString}),
-              ap["continue"]);
-    EXPECT_EQ(std::vector<std::string>({expected_target2, expected_target1}),
-              ap["target"]);
-}
-
-/** @brief ArgumentParser should print usage information when given a help
- *         argument anywhere in the arguments array
- */
-TEST_F(ArgumentTest, ShortOptionHelp)
-{
-    std::string arg_extra = "extra";
-    std::string arg_help = "-h";
-    char* const args[] = {&arg0[0], &arg_extra[0], &arg_help[0], nullptr};
-    EXPECT_EXIT(ArgumentParser(sizeof(args) / sizeof(char*) - 1, args),
-                ::testing::ExitedWithCode(255), clean_usage_regex);
-}
-
-/** @brief ArgumentParser should print usage information when given a help
- *         argument anywhere in the arguments array
- */
-TEST_F(ArgumentTest, LongOptionHelp)
-{
-    std::string arg_help = "--help";
-    std::string arg_extra = "extra";
-    char* const args[] = {&arg0[0], &arg_help[0], &arg_extra[0], nullptr};
-    EXPECT_EXIT(ArgumentParser(sizeof(args) / sizeof(char*) - 1, args),
-                ::testing::ExitedWithCode(255), clean_usage_regex);
-}
-
-/** @brief ArgumentParser should print an invalid argument error and
- *         usage information when given an invalid argument anywhere
- *         in the arguments array
- */
-TEST_F(ArgumentTest, InvalidOptionHelp)
-{
-    std::string arg_continue = "--continue";
-    std::string arg_bad = "--bad_arg";
-    std::string arg_target = "--target=/unused-path";
-    char* const args[] = {&arg0[0], &arg_continue[0], &arg_bad[0],
-                          &arg_target[0], nullptr};
-    EXPECT_EXIT(ArgumentParser(sizeof(args) / sizeof(char*) - 1, args),
-                ::testing::ExitedWithCode(255), invalid_arg_regex);
-}
-
-} // namespace watchdog
-} // namespace phosphor
diff --git a/test/argument_test.hpp b/test/argument_test.hpp
deleted file mode 100644
index 46e8762..0000000
--- a/test/argument_test.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#include <string>
-
-#include <gtest/gtest.h>
-
-namespace phosphor
-{
-namespace watchdog
-{
-
-class ArgumentTest : public testing::Test
-{
-  protected:
-    void SetUp() override;
-
-    std::string arg0;
-};
-
-} // namespace watchdog
-} // namespace phosphor