Skip to content

Commit fe95f4a

Browse files
committed
use TCLAP to parse program options
Remove dependency to boost::program_options.
1 parent 4ccddd5 commit fe95f4a

File tree

5 files changed

+34
-60
lines changed

5 files changed

+34
-60
lines changed

.github/workflows/run-all.yml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
g++ \
2525
gcovr \
2626
git \
27-
libboost-program-options-dev \
2827
libboost-system-dev \
2928
libboost-test-dev \
3029
make \

CMakeLists.txt

+1-8
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ endif()
114114
set(BOOST_MIN_VERSION "1.70")
115115

116116
set(Boost_USE_STATIC_RUNTIME OFF)
117-
set(CUKE_CORE_BOOST_LIBS system program_options)
117+
set(CUKE_CORE_BOOST_LIBS system)
118118
if(CUKE_ENABLE_BOOST_TEST)
119119
# "An external test runner utility is required to link with dynamic library" (Boost User's Guide)
120120
set(Boost_USE_STATIC_LIBS OFF)
@@ -155,13 +155,6 @@ if(Boost_SYSTEM_LIBRARY AND NOT TARGET Boost::system)
155155
)
156156
endif()
157157
endif()
158-
if(Boost_PROGRAM_OPTIONS_LIBRARY AND NOT TARGET Boost::program_options)
159-
add_library(Boost::program_options ${LIBRARY_TYPE} IMPORTED)
160-
set_target_properties(Boost::program_options PROPERTIES
161-
"IMPORTED_LOCATION" "${Boost_PROGRAM_OPTIONS_LIBRARY}"
162-
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
163-
)
164-
endif()
165158
if(Boost_UNIT_TEST_FRAMEWORK_LIBRARY AND NOT TARGET Boost::unit_test_framework)
166159
add_library(Boost::unit_test_framework ${LIBRARY_TYPE} IMPORTED)
167160
set_target_properties(Boost::unit_test_framework PROPERTIES

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ It relies on a few executables:
2323
It relies on a few libraries:
2424

2525
* [Boost](http://www.boost.org/) 1.70.
26-
Required libraries: *system* and *program_options*.
26+
Required libraries: *system*.
2727
Optional library for Boost Test driver: *test*.
2828
* [GTest](http://code.google.com/p/googletest/) 1.6 or later.
2929
Optional for the GTest driver. By default downloaded and built by CMake.

src/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ target_compile_definitions(cucumber-cpp PRIVATE
130130
CUKE_VERSION="${CUKE_VERSION}"
131131
)
132132

133-
target_link_libraries(cucumber-cpp
134-
PRIVATE
135-
Boost::program_options
136-
)
137-
138133
include(GNUInstallDirs)
139134
install(DIRECTORY ${CUKE_INCLUDE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
140135
install(

src/main.cpp

+32-45
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <cucumber-cpp/internal/connectors/wire/WireServer.hpp>
44
#include <cucumber-cpp/internal/connectors/wire/WireProtocol.hpp>
55
#include <iostream>
6-
#include <boost/program_options.hpp>
76
#include <memory>
7+
#include <tclap/CmdLine.h>
88

99
namespace {
1010

@@ -43,58 +43,45 @@ void acceptWireProtocol(
4343
}
4444

4545
int CUCUMBER_CPP_EXPORT main(int argc, char** argv) {
46-
using boost::program_options::value;
47-
boost::program_options::options_description optionDescription("Allowed options");
48-
optionDescription.add_options()("help,h", "help for cucumber-cpp")(
49-
"verbose,v", "verbose output"
50-
)("version", "version of cucumber-cpp"
51-
)("listen,l", value<std::string>(), "listening address of wireserver"
52-
)("port,p",
53-
value<int>(),
54-
"listening port of wireserver, use '0' (zero) to select an ephemeral port")
55-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
56-
("unix,u",
57-
value<std::string>(),
58-
"listening unix socket of wireserver (disables listening on port)")
59-
#endif
60-
;
61-
boost::program_options::variables_map optionVariableMap;
62-
boost::program_options::store(
63-
boost::program_options::parse_command_line(argc, argv, optionDescription), optionVariableMap
64-
);
65-
boost::program_options::notify(optionVariableMap);
66-
67-
if (optionVariableMap.count("help")) {
68-
std::cerr << optionDescription << std::endl;
69-
exit(1);
70-
}
46+
TCLAP::CmdLine cmd("C++ Cucumber wireserver", ' ', CUKE_VERSION);
7147

72-
if (optionVariableMap.count("version")) {
73-
std::cout << CUKE_VERSION << std::endl;
74-
exit(0);
75-
}
48+
TCLAP::SwitchArg verboseArg("v", "verbose", "Verbose output", cmd, false);
49+
TCLAP::ValueArg<std::string> listenArg(
50+
"l", "listen", "Listening address of wireserver", false, "127.0.0.1", "string"
51+
);
52+
cmd.add(listenArg);
53+
TCLAP::ValueArg<int> portArg(
54+
"p",
55+
"port",
56+
"Listening port of wireserver, use '0' (zero) to select an ephemeral port",
57+
false,
58+
3902,
59+
"int"
60+
);
61+
cmd.add(portArg);
7662

77-
std::string listenHost("127.0.0.1");
78-
if (optionVariableMap.count("listen")) {
79-
listenHost = optionVariableMap["listen"].as<std::string>();
80-
}
63+
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
64+
TCLAP::ValueArg<std::string> unixArg(
65+
"u",
66+
"unix",
67+
"Listening unix socket of wireserver (disables listening on port)",
68+
false,
69+
"",
70+
"string"
71+
);
72+
cmd.add(unixArg);
73+
#endif
8174

82-
int port = 3902;
83-
if (optionVariableMap.count("port")) {
84-
port = optionVariableMap["port"].as<int>();
85-
}
75+
cmd.parse(argc, argv);
8676

8777
std::string unixPath;
78+
std::string listenHost = listenArg.getValue();
79+
int port = portArg.getValue();
8880
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
89-
if (optionVariableMap.count("unix")) {
90-
unixPath = optionVariableMap["unix"].as<std::string>();
91-
}
81+
unixPath = unixArg.getValue();
9282
#endif
9383

94-
bool verbose = false;
95-
if (optionVariableMap.count("verbose")) {
96-
verbose = true;
97-
}
84+
bool verbose = verboseArg.getValue();
9885

9986
try {
10087
acceptWireProtocol(listenHost, port, unixPath, verbose);

0 commit comments

Comments
 (0)