IVGCVSW-5283 Switch tests/profiling/gatordmock over to cxxopts
authorMatthew Sloyan <matthew.sloyan@arm.com>
Wed, 30 Sep 2020 12:07:51 +0000 (13:07 +0100)
committerTeresaARM <teresa.charlinreyes@arm.com>
Thu, 1 Oct 2020 13:26:33 +0000 (13:26 +0000)
Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com>
Change-Id: I4f06a414d6bd5f18c2ced882ac518052ed371cfc

tests/profiling/gatordmock/CommandLineProcessor.cpp

index 2903dbb..c1b6a6b 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "CommandLineProcessor.hpp"
 
-#include <boost/program_options.hpp>
+#include <cxxopts/cxxopts.hpp>
 #include <iostream>
 
 namespace armnn
@@ -15,19 +15,24 @@ namespace gatordmock
 
 bool CommandLineProcessor::ProcessCommandLine(int argc, char *argv[])
 {
-    namespace po = boost::program_options;
-    po::options_description desc("Options");
+    cxxopts::Options options("GatordMock",
+                             "Simulate a Gatord server to interact with ArmNN external profiling.");
+
     try
     {
-        desc.add_options()
-                ("help,h", "Display help messages")
-                ("file,f",  po::value<std::string>(&m_File),
-                                 "The path to the file that contains instructions for the mock gatord")
-                ("namespace,n", po::value<std::string>(&m_UdsNamespace)->default_value("gatord_namespace"),
-                                "The Unix domain socket namespace this server will bind to.\n"
-                                "This will always be prepended with \\0 to use the abstract namespace")
-                ("echo,e", po::bool_switch(&m_Echo)->default_value(false),
-                                "Echo packets sent and received to stdout. Disabled by default.\n");
+        options.add_options()
+            ("h,help", "Display help messages")
+            ("f,file",
+                "The path to the file that contains instructions for the mock gatord.",
+                cxxopts::value<std::string>(m_File))
+            ("n,namespace",
+                "The Unix domain socket namespace this server will bind to.\n"
+                "This will always be prepended with \\0 to use the abstract namespace",
+                cxxopts::value<std::string>(m_UdsNamespace)->default_value("gatord_namespace"))
+            ("e,echo",
+                "Echo packets sent and received to stdout. Disabled by default. "
+                "Default value = false.",
+                cxxopts::value<bool>(m_Echo)->default_value("false"));
     }
     catch (const std::exception& e)
     {
@@ -35,32 +40,32 @@ bool CommandLineProcessor::ProcessCommandLine(int argc, char *argv[])
         return false;
     }
 
-    po::variables_map vm;
     try
     {
-        po::store(po::parse_command_line(argc, argv, desc), vm);
+        auto result = options.parse(argc, argv);
 
-        if (vm.count("help"))
+        if (result.count("help"))
         {
-            std::cout << "Simulate a Gatord server to interact with ArmNN external profiling." << std::endl;
-            std::cout << std::endl;
-            std::cout << desc << std::endl;
+            std::cout << options.help() << std::endl;
             return false;
         }
+
         // Currently the file parameter is mandatory.
-        if (!vm.count("file"))
+        if (!result.count("file"))
         {
-            std::cout << std::endl << "*** Expected --file or -f parameter." << std::endl;
-            std::cout << std::endl;
-            std::cout << desc << std::endl;
+            std::cout << "-f/--file parameter is mandatory." << std::endl;
             return false;
         }
-        po::notify(vm);
+
+        // Sets bool value correctly.
+        if (result.count("echo"))
+        {
+            m_Echo = true;
+        }
     }
-    catch (const po::error& e)
+    catch (const cxxopts::OptionException& e)
     {
-        std::cerr << e.what() << std::endl << std::endl;
-        std::cerr << desc << std::endl;
+        std::cerr << e.what() << std::endl;
         return false;
     }