1 #include "GetoptCommandLineParser.h"
9 #include "CommandLineParserUtils.h"
10 #include "WalkerException.h"
14 static struct option options
[] = {
15 {"help", no_argument
, nullptr, 'h'},
16 {"version", no_argument
, nullptr, 'v'},
17 {"deep", no_argument
, nullptr, 'd'},
18 {"skip-ssl-verification", no_argument
, nullptr, 255},
19 {"dot-out", required_argument
, nullptr, 'o'},
20 {"json-cache", required_argument
, nullptr, 'j'},
21 {nullptr, 0, nullptr, 0},
24 std::string
GetoptCommandLineParser::getValue(
25 CommandLineParserBase::CommandLineOptions option
)
27 return setOptions
.find(CommandLineParserUtils::getStringFlag(option
))
31 bool GetoptCommandLineParser::hasSet(
32 CommandLineParserBase::CommandLineOptions flag
)
34 return setOptions
.find(CommandLineParserUtils::getStringFlag(flag
)) !=
38 void GetoptCommandLineParser::parse(int argc
, char** argv
)
41 // ignoreing long option index
45 while((opt
= getopt_long(argc
, argv
, "vhdj:o:", options
, &index
)) != -1) {
48 setOptions
.insert(std::make_pair("help", "1"));
51 setOptions
.insert(std::make_pair("version", "1"));
54 setOptions
.insert(std::make_pair("deep", "1"));
57 setOptions
.insert(std::make_pair("json-cache", optarg
));
60 setOptions
.insert(std::make_pair("dot-out", optarg
));
64 std::string errorMsg
= "Missing argument or unknown option: -";
65 errorMsg
.push_back(optopt
);
67 throw WalkerException(errorMsg
);
73 setOptions
.insert(std::make_pair("url", argv
[optind
]));
77 static void helpFormatter(const std::string
& option
,
78 const std::string
& description
)
80 std::cout
<< std::setw(5) << "" << std::left
<< std::setw(20) << option
81 << " " << description
<< std::endl
;
84 void GetoptCommandLineParser::printHelp()
86 std::cout
<< "walker usage: walker [options] <URL>" << std::endl
;
87 std::cout
<< " walker -j <file> -o <file> [URL]" << std::endl
;
88 std::cout
<< std::endl
;
90 helpFormatter("-h, --help", "print program help");
91 helpFormatter("-v, --version", "print program version");
92 helpFormatter("-d, --deep",
93 "whether to fetch and analyze linked articles as well");
94 helpFormatter("-j, --json-cache", "cache file in JSON format");
95 helpFormatter("-o, --dot-out", "output file for dot/graphviz");
97 std::cout
<< std::endl
;
99 std::cout
<< "The environment variable CURL_CA_BUNDLE is read for"
100 " finding a CA bundle"
102 << " for curl." << std::endl
;
104 std::cout
<< std::endl
;
106 } // namespace WikiWalker