Skip to content

Commit 9763b12

Browse files
MCOL-5880: get rid of CLI11 dep in favour of boost::program_options
1 parent 9618ff5 commit 9763b12

File tree

5 files changed

+84
-52
lines changed

5 files changed

+84
-52
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ SET (ENGINE_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
136136
INCLUDE(columnstore_version)
137137
INCLUDE(misc)
138138
INCLUDE(boost)
139-
INCLUDE(CLI11)
140139
INCLUDE(thrift)
141140

142141
FIND_PACKAGE(BISON)

cmake/CLI11.cmake

-15
This file was deleted.

versioning/BRM/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ target_link_libraries(mcs-load-em ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENG
122122
install(TARGETS mcs-load-em DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine)
123123

124124
add_executable(mcs-load-brm-from-file load_brm_from_file.cpp)
125-
target_link_libraries(mcs-load-brm-from-file ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} CLI11)
125+
target_link_libraries(mcs-load-brm-from-file ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} boost_program_options)
126126
install(TARGETS mcs-load-brm-from-file DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine)
127127

128128
add_executable(mcs-shmem-locks shmem_locks.cpp)
129-
target_link_libraries(mcs-shmem-locks ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} CLI11)
129+
target_link_libraries(mcs-shmem-locks ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} boost_program_options)
130130
install(TARGETS mcs-shmem-locks DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine)

versioning/BRM/load_brm_from_file.cpp

+29-14
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
#include <cstdlib>
3131
#include <cassert>
3232
#include <limits>
33+
34+
#include <boost/program_options.hpp>
35+
namespace po = boost::program_options;
36+
3337
using namespace std;
3438

35-
#include "CLI11.hpp"
3639
#include "extentmap.h"
3740

38-
static const char* BIN_NAME = "mcs-load-brm-from-file";
39-
4041
template <typename T>
4142
T parseField(std::stringstream& ss, const char delimiter)
4243
{
@@ -75,23 +76,37 @@ BRM::EMEntry parseLine(const std::string& line, char delimiter = '|')
7576

7677
int main(int argc, char** argv)
7778
{
78-
CLI::App app{BIN_NAME};
79-
app.description(
80-
"A tool to build Extent Map image file from its text representation. A text representation can be obtained using 'editem -i'"
79+
po::options_description desc(
80+
"A tool to build Extent Map image file from its text representation. A text representation can be "
81+
"obtained using 'editem -i'"
8182
"display the lock state.");
83+
8284
std::string srcFilename;
8385
std::string dstFilename;
8486
bool debug = false;
8587

86-
app.add_option("-i,--input-filename", srcFilename,
87-
"Extent Map as its text representation.")
88-
->required();
89-
app.add_option("-o,--output-filename", dstFilename,
90-
"Extent Map output image file, default as input-filename.out")
91-
->default_val("");
92-
app.add_option("-d,--debug", debug, "Print extra output")->default_val(false);
88+
// clang-format off
89+
desc.add_options()
90+
("help", "produce help message")
91+
("input-filename,i",
92+
po::value<std::string>(&srcFilename)->required(),
93+
"Extent Map as its text representation.")
94+
("output-filename,o",
95+
po::value<std::string>(&dstFilename)->default_value(""),
96+
"Extent Map output image file, default as input-filename.out")
97+
("debug,d", po::bool_switch(&debug)->default_value(false), "Print extra output");
98+
// clang-format on
99+
100+
po::variables_map vm;
101+
po::store(po::parse_command_line(argc, argv, desc), vm);
102+
103+
if (argc == 1 || vm.count("help"))
104+
{
105+
cout << desc << "\n";
106+
return 1;
107+
}
93108

94-
CLI11_PARSE(app, argc, argv);
109+
po::notify(vm);
95110

96111
ifstream in(srcFilename);
97112
int e = errno;

versioning/BRM/shmem_locks.cpp

+53-20
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
#include <stdlib.h>
2222
#include <rwlock.h>
2323

24-
#include "CLI11.hpp"
25-
2624
using namespace std;
2725
using namespace rwlock;
2826

29-
static const char* BIN_NAME = "mcs-load-brm-from-file";
27+
#include <boost/program_options.hpp>
28+
namespace po = boost::program_options;
3029

3130
std::string getShmemLocksList()
3231
{
@@ -85,31 +84,66 @@ int lockOp(size_t minLockId, size_t maxLockId, bool lock, bool read)
8584
return 0;
8685
}
8786

87+
void conflicting_options(const boost::program_options::variables_map& vm, const std::string& opt1,
88+
const std::string& opt2)
89+
{
90+
if (vm.count(opt1) && !vm[opt1].defaulted() && vm.count(opt2) && !vm[opt2].defaulted())
91+
{
92+
throw std::logic_error(std::string("Conflicting options '") + opt1 + "' and '" + opt2 + "'.");
93+
}
94+
}
95+
96+
template <class T>
97+
void check_value(const boost::program_options::variables_map& vm, const std::string& opt1, T lower_bound,
98+
T upper_bound)
99+
{
100+
auto value = vm[opt1].as<T>();
101+
if (value < lower_bound || value >= upper_bound)
102+
{
103+
throw std::logic_error(std::string("Option '") + opt1 + "' is out of range.: " + std::to_string(value));
104+
}
105+
}
106+
88107
int main(int argc, char** argv)
89108
{
90-
CLI::App app{BIN_NAME};
91-
app.description(
92-
"A tool to operate or view shmem locks. If neither read nor write operation is specified, the tool will "
93-
"display the lock state.");
94-
uint8_t lockId;
109+
int lockId;
95110
bool debug = false;
96111
bool read = false;
97112
bool write = false;
98113
bool lock = false;
99114
bool unlock = false;
100115

101-
app.add_option<uint8_t>("-i, --lock-id", lockId, "Shmem lock numerical id: " + getShmemLocksList())
102-
->expected(0, RWLockNames.size())
103-
->required();
104-
app.add_flag("-r, --read-lock", read, "Use read lock.")->default_val(false);
105-
app.add_flag("-w, --write-lock", write, "Use write lock..")->default_val(false)->excludes("-r");
106-
app.add_flag("-l, --lock", lock, "Lock the corresponding shmem lock.")->default_val(false);
107-
app.add_flag("-u, --unlock", unlock, "Unlock the corresponding shmem write lock.")
108-
->default_val(false)
109-
->excludes("-l");
110-
app.add_flag("-d,--debug", debug, "Print extra output.")->default_val(false);
116+
po::options_description desc(
117+
"A tool to operate or view shmem locks. If neither read nor write operation is specified, the tool "
118+
"will "
119+
"display the lock state.");
120+
121+
std::string lockid_description = std::string("Shmem lock numerical id: ") + getShmemLocksList();
122+
123+
// clang-format off
124+
desc.add_options()("help", "produce help message")
125+
("lock-id,i", po::value<int>(&lockId)->required(), lockid_description.c_str())
126+
("read-lock,r", po::bool_switch(&read)->default_value(false), "Use read lock.")
127+
("write-lock,w", po::bool_switch(&write)->default_value(false), "Use write lock.")
128+
("lock,l", po::bool_switch(&lock)->default_value(false), "Lock the corresponding shmem lock.")
129+
("unlock,u", po::bool_switch(&unlock)->default_value(false), "Unlock the corresponding shmem write lock.")
130+
("debug,d", po::bool_switch(&debug)->default_value(false), "Print extra output.");
131+
// clang-format on
132+
133+
po::variables_map vm;
134+
po::store(po::parse_command_line(argc, argv, desc), vm);
111135

112-
CLI11_PARSE(app, argc, argv);
136+
if (argc == 1 || vm.count("help"))
137+
{
138+
cout << desc << "\n";
139+
return 1;
140+
}
141+
142+
conflicting_options(vm, "lock", "unlock");
143+
conflicting_options(vm, "read-lock", "write-lock");
144+
check_value<int>(vm, "lock-id", 0, RWLockNames.size());
145+
146+
po::notify(vm);
113147

114148
if (!read && !write)
115149
{
@@ -125,4 +159,3 @@ int main(int argc, char** argv)
125159

126160
return 0;
127161
}
128-

0 commit comments

Comments
 (0)