Skip to content

Commit

Permalink
use TCLAP to parse program options
Browse files Browse the repository at this point in the history
Remove dependency to boost::program_options.
  • Loading branch information
ursfassler committed Dec 28, 2023
1 parent 8a0d16b commit 827008c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 60 deletions.
1 change: 0 additions & 1 deletion .github/workflows/run-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
g++ \
gcovr \
git \
libboost-program-options-dev \
libboost-system-dev \
libboost-test-dev \
make \
Expand Down
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
77 changes: 32 additions & 45 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <cucumber-cpp/internal/connectors/wire/WireServer.hpp>
#include <cucumber-cpp/internal/connectors/wire/WireProtocol.hpp>
#include <iostream>
#include <boost/program_options.hpp>
#include <memory>
#include <tclap/CmdLine.h>

namespace {

Expand Down Expand Up @@ -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<std::string>(), "listening address of wireserver"
)("port,p",
value<int>(),
"listening port of wireserver, use '0' (zero) to select an ephemeral port")
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
("unix,u",
value<std::string>(),
"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<std::string> listenArg(
"l", "listen", "Listening address of wireserver", false, "127.0.0.1", "string"
);
cmd.add(listenArg);
TCLAP::ValueArg<int> 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<std::string>();
}
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
TCLAP::ValueArg<std::string> 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<int>();
}
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<std::string>();
}
unixPath = unixArg.getValue();
#endif

bool verbose = false;
if (optionVariableMap.count("verbose")) {
verbose = true;
}
bool verbose = verboseArg.getValue();

try {
acceptWireProtocol(listenHost, port, unixPath, verbose);
Expand Down

0 comments on commit 827008c

Please sign in to comment.