|
15 | 15 | #include<string> |
16 | 16 | #include<utility> |
17 | 17 | #include<iostream> |
18 | | - |
19 | | -namespacepo= boost::program_options; |
| 18 | +#include"cxxopts.hpp" |
20 | 19 |
|
21 | 20 | intmain(int argc,char* argv[]) { |
22 | 21 | usingnamespaceboost::network; |
23 | | - po::options_descriptionoptions("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"); |
29 | 22 |
|
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::Optionsoptions(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); |
46 | 33 |
|
47 | | -if (vm.count("help")) { |
48 | | - std::cout << options << std::endl; |
| 34 | +if (options.count("help")) { |
| 35 | + std::cout << options.help({"","Group"}) << std::endl; |
49 | 36 | return EXIT_SUCCESS; |
50 | 37 | } |
51 | 38 |
|
52 | | -if (vm.count("source") <1) { |
| 39 | +if (options.count("source") <1) { |
53 | 40 | std::cout <<"Error: Source URL required." << std::endl; |
54 | | - std::cout << options << std::endl; |
| 41 | + std::cout << options.help({"","Group"}) << std::endl; |
55 | 42 | return EXIT_FAILURE; |
56 | 43 | } |
57 | 44 |
|
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; |
60 | 48 |
|
61 | 49 | http::client::requestrequest(source); |
62 | 50 | http::client::string_type destination_ =host(request); |
|