Skip to content

Thread group #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Removed depenency on boost program_options (replaced with cxxopts, wh…
…ich only depends on C++11).
  • Loading branch information
glynos committed Jan 30, 2016
commit a7d48af2d972dfeeac9b57815764bcf3e3070069
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "libs/network/doc/_ext/breathe"]
path = libs/network/doc/_ext/breathe
url = https://github.com/michaeljones/breathe.git
[submodule "deps/cxxopts"]
path = deps/cxxopts
url = https://github.com/jarro2783/cxxopts.git
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
# Always use multi-threaded Boost libraries.
set(Boost_USE_MULTI_THREADED ON)

find_package(Boost 1.57.0
REQUIRED system filesystem program_options)
find_package(Boost 1.57.0 REQUIRED system filesystem)

if (CPP-NETLIB_ENABLE_HTTPS)
find_package( OpenSSL )
Expand Down
1 change: 1 addition & 0 deletions deps/cxxopts
Submodule cxxopts added at aec97a
1 change: 1 addition & 0 deletions libs/network/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# http://www.boost.org/LICENSE_1_0.txt)

include_directories(${CPP-NETLIB_SOURCE_DIR})
include_directories(${CPP-NETLIB_SOURCE_DIR}/deps/cxxopts/src)
if (OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
endif (OPENSSL_FOUND)
Expand Down
48 changes: 18 additions & 30 deletions libs/network/example/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,36 @@
#include <string>
#include <utility>
#include <iostream>

namespace po = boost::program_options;
#include "cxxopts.hpp"

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

po::positional_options_description positional_options;
positional_options.add("source", 1);
po::variables_map vm;
try {
po::store(po::command_line_parser(argc, argv)
.options(options)
.positional(positional_options)
.run(),
vm);
po::notify(vm);
}
catch (std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
std::cout << options << std::endl;
return EXIT_FAILURE;
}
cxxopts::Options options(argv[0], "Allowed options");
options.add_options()
("h,help", "produce help message")
("H,headers", "print headers")
("S,status", "print status and message")
("s,source", "source URL", cxxopts::value<std::string>())
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks really nice!


options.parse_positional(std::vector<std::string>{"source"});
options.parse(argc, argv);

if (vm.count("help")) {
std::cout << options << std::endl;
if (options.count("help")) {
std::cout << options.help({"", "Group"}) << std::endl;
return EXIT_SUCCESS;
}

if (vm.count("source") < 1) {
if (options.count("source") < 1) {
std::cout << "Error: Source URL required." << std::endl;
std::cout << options << std::endl;
std::cout << options.help({"", "Group"}) << std::endl;
return EXIT_FAILURE;
}

show_headers = vm.count("headers") ? true : false;
bool show_status = vm.count("status") ? true : false;
std::string source = options["source"].as<std::string>();
bool show_headers = options.count("headers") ? true : false;
bool show_status = options.count("status") ? true : false;

http::client::request request(source);
http::client::string_type destination_ = host(request);
Expand Down