From 827008cdac8d318916cea2b193d8bd2262c273fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Thu, 28 Dec 2023 17:33:05 +0100 Subject: [PATCH] use TCLAP to parse program options Remove dependency to boost::program_options. --- .github/workflows/run-all.yml | 1 - CMakeLists.txt | 9 +--- README.md | 2 +- src/CMakeLists.txt | 5 --- src/main.cpp | 77 +++++++++++++++-------------------- 5 files changed, 34 insertions(+), 60 deletions(-) diff --git a/.github/workflows/run-all.yml b/.github/workflows/run-all.yml index 7c6aeef0..7b74ab55 100644 --- a/.github/workflows/run-all.yml +++ b/.github/workflows/run-all.yml @@ -22,7 +22,6 @@ jobs: g++ \ gcovr \ git \ - libboost-program-options-dev \ libboost-system-dev \ libboost-test-dev \ make \ diff --git a/CMakeLists.txt b/CMakeLists.txt index e1700b86..1f383185 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,7 +114,7 @@ endif() set(BOOST_MIN_VERSION "1.70") set(Boost_USE_STATIC_RUNTIME OFF) -set(CUKE_CORE_BOOST_LIBS system program_options) +set(CUKE_CORE_BOOST_LIBS system) if(CUKE_ENABLE_BOOST_TEST) # "An external test runner utility is required to link with dynamic library" (Boost User's Guide) set(Boost_USE_STATIC_LIBS OFF) @@ -155,13 +155,6 @@ if(Boost_SYSTEM_LIBRARY AND NOT TARGET Boost::system) ) endif() endif() -if(Boost_PROGRAM_OPTIONS_LIBRARY AND NOT TARGET Boost::program_options) - add_library(Boost::program_options ${LIBRARY_TYPE} IMPORTED) - set_target_properties(Boost::program_options PROPERTIES - "IMPORTED_LOCATION" "${Boost_PROGRAM_OPTIONS_LIBRARY}" - "INTERFACE_LINK_LIBRARIES" "Boost::boost" - ) -endif() if(Boost_UNIT_TEST_FRAMEWORK_LIBRARY AND NOT TARGET Boost::unit_test_framework) add_library(Boost::unit_test_framework ${LIBRARY_TYPE} IMPORTED) set_target_properties(Boost::unit_test_framework PROPERTIES diff --git a/README.md b/README.md index f8dc3f5d..af11ae87 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ It relies on a few executables: It relies on a few libraries: * [Boost](http://www.boost.org/) 1.70. - Required libraries: *system* and *program_options*. + Required libraries: *system*. Optional library for Boost Test driver: *test*. * [GTest](http://code.google.com/p/googletest/) 1.6 or later. Optional for the GTest driver. By default downloaded and built by CMake. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3579e695..922b58ae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,11 +130,6 @@ target_compile_definitions(cucumber-cpp PRIVATE CUKE_VERSION="${CUKE_VERSION}" ) -target_link_libraries(cucumber-cpp - PRIVATE - Boost::program_options -) - include(GNUInstallDirs) install(DIRECTORY ${CUKE_INCLUDE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install( diff --git a/src/main.cpp b/src/main.cpp index 44031d1f..fd7006fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include namespace { @@ -43,58 +43,45 @@ void acceptWireProtocol( } int CUCUMBER_CPP_EXPORT main(int argc, char** argv) { - using boost::program_options::value; - boost::program_options::options_description optionDescription("Allowed options"); - optionDescription.add_options()("help,h", "help for cucumber-cpp")( - "verbose,v", "verbose output" - )("version", "version of cucumber-cpp" - )("listen,l", value(), "listening address of wireserver" - )("port,p", - value(), - "listening port of wireserver, use '0' (zero) to select an ephemeral port") -#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) - ("unix,u", - value(), - "listening unix socket of wireserver (disables listening on port)") -#endif - ; - boost::program_options::variables_map optionVariableMap; - boost::program_options::store( - boost::program_options::parse_command_line(argc, argv, optionDescription), optionVariableMap - ); - boost::program_options::notify(optionVariableMap); - - if (optionVariableMap.count("help")) { - std::cerr << optionDescription << std::endl; - exit(1); - } + TCLAP::CmdLine cmd("C++ Cucumber wireserver", ' ', CUKE_VERSION); - if (optionVariableMap.count("version")) { - std::cout << CUKE_VERSION << std::endl; - exit(0); - } + TCLAP::SwitchArg verboseArg("v", "verbose", "Verbose output", cmd, false); + TCLAP::ValueArg listenArg( + "l", "listen", "Listening address of wireserver", false, "127.0.0.1", "string" + ); + cmd.add(listenArg); + TCLAP::ValueArg portArg( + "p", + "port", + "Listening port of wireserver, use '0' (zero) to select an ephemeral port", + false, + 3902, + "int" + ); + cmd.add(portArg); - std::string listenHost("127.0.0.1"); - if (optionVariableMap.count("listen")) { - listenHost = optionVariableMap["listen"].as(); - } +#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) + TCLAP::ValueArg unixArg( + "u", + "unix", + "Listening unix socket of wireserver (disables listening on port)", + false, + "", + "string" + ); + cmd.add(unixArg); +#endif - int port = 3902; - if (optionVariableMap.count("port")) { - port = optionVariableMap["port"].as(); - } + cmd.parse(argc, argv); std::string unixPath; + std::string listenHost = listenArg.getValue(); + int port = portArg.getValue(); #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) - if (optionVariableMap.count("unix")) { - unixPath = optionVariableMap["unix"].as(); - } + unixPath = unixArg.getValue(); #endif - bool verbose = false; - if (optionVariableMap.count("verbose")) { - verbose = true; - } + bool verbose = verboseArg.getValue(); try { acceptWireProtocol(listenHost, port, unixPath, verbose);