Skip to content

Commit a7d48af

Browse files
committed
Removed depenency on boost program_options (replaced with cxxopts, which only depends on C++11).
1 parent 8797e4d commit a7d48af

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "libs/network/doc/_ext/breathe"]
88
path = libs/network/doc/_ext/breathe
99
url = https://github.com/michaeljones/breathe.git
10+
[submodule "deps/cxxopts"]
11+
path = deps/cxxopts
12+
url = https://github.com/jarro2783/cxxopts.git

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
4646
# Always use multi-threaded Boost libraries.
4747
set(Boost_USE_MULTI_THREADED ON)
4848

49-
find_package(Boost 1.57.0
50-
REQUIRED system filesystem program_options)
49+
find_package(Boost 1.57.0 REQUIRED system filesystem)
5150

5251
if (CPP-NETLIB_ENABLE_HTTPS)
5352
find_package( OpenSSL )

deps/cxxopts

Submodule cxxopts added at aec97a6

libs/network/example/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# http://www.boost.org/LICENSE_1_0.txt)
55

66
include_directories(${CPP-NETLIB_SOURCE_DIR})
7+
include_directories(${CPP-NETLIB_SOURCE_DIR}/deps/cxxopts/src)
78
if (OPENSSL_FOUND)
89
include_directories(${OPENSSL_INCLUDE_DIR})
910
endif (OPENSSL_FOUND)

libs/network/example/http_client.cpp

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,36 @@
1515
#include <string>
1616
#include <utility>
1717
#include <iostream>
18-
19-
namespace po = boost::program_options;
18+
#include "cxxopts.hpp"
2019

2120
int main(int argc, char* argv[]) {
2221
using namespace boost::network;
23-
po::options_description options("Allowed options");
24-
std::string output_filename, source;
25-
bool show_headers;
26-
options.add_options()("help,h", "produce help message")(
27-
"headers,H", "print headers")("status,S", "print status and message")(
28-
"source,s", po::value<std::string>(&source), "source URL");
2922

30-
po::positional_options_description positional_options;
31-
positional_options.add("source", 1);
32-
po::variables_map vm;
33-
try {
34-
po::store(po::command_line_parser(argc, argv)
35-
.options(options)
36-
.positional(positional_options)
37-
.run(),
38-
vm);
39-
po::notify(vm);
40-
}
41-
catch (std::exception& e) {
42-
std::cout << "Error: " << e.what() << std::endl;
43-
std::cout << options << std::endl;
44-
return EXIT_FAILURE;
45-
}
23+
cxxopts::Options options(argv[0], "Allowed options");
24+
options.add_options()
25+
("h,help", "produce help message")
26+
("H,headers", "print headers")
27+
("S,status", "print status and message")
28+
("s,source", "source URL", cxxopts::value<std::string>())
29+
;
30+
31+
options.parse_positional(std::vector<std::string>{"source"});
32+
options.parse(argc, argv);
4633

47-
if (vm.count("help")) {
48-
std::cout << options << std::endl;
34+
if (options.count("help")) {
35+
std::cout << options.help({"", "Group"}) << std::endl;
4936
return EXIT_SUCCESS;
5037
}
5138

52-
if (vm.count("source") < 1) {
39+
if (options.count("source") < 1) {
5340
std::cout << "Error: Source URL required." << std::endl;
54-
std::cout << options << std::endl;
41+
std::cout << options.help({"", "Group"}) << std::endl;
5542
return EXIT_FAILURE;
5643
}
5744

58-
show_headers = vm.count("headers") ? true : false;
59-
bool show_status = vm.count("status") ? true : false;
45+
std::string source = options["source"].as<std::string>();
46+
bool show_headers = options.count("headers") ? true : false;
47+
bool show_status = options.count("status") ? true : false;
6048

6149
http::client::request request(source);
6250
http::client::string_type destination_ = host(request);

0 commit comments

Comments
 (0)