feat: handle exception
This commit is contained in:
parent
0befc5bc93
commit
39adf93e46
17
src/main.cpp
17
src/main.cpp
|
@ -65,8 +65,23 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
options.parse_positional({"filenames"});
|
options.parse_positional({"filenames"});
|
||||||
|
|
||||||
|
options.allow_unrecognised_options();
|
||||||
|
|
||||||
// Parse options the usual way
|
// Parse options the usual way
|
||||||
auto result = options.parse(argc, argv);
|
cxxopts::ParseResult result;
|
||||||
|
try {
|
||||||
|
result = options.parse(argc, argv);
|
||||||
|
} catch(cxxopts::exceptions::parsing const& e) {
|
||||||
|
std::cout << options.help() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// print usage message if unrecognised options are present
|
||||||
|
if (result.unmatched().size() > 0)
|
||||||
|
{
|
||||||
|
std::cout << options.help() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// display help message
|
// display help message
|
||||||
if (result.count("help"))
|
if (result.count("help"))
|
||||||
|
|
Loading…
Reference in New Issue