-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_modes.cpp
49 lines (42 loc) · 1.38 KB
/
parser_modes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include "simple-args-parser.hpp"
/*
Try for ./parser_modes -s test -unknown test
*/
int main(int argc, char **argv)
{
args::Parser args_parser_skip_unknown(args::ParserMode::IGNORE_UNKNOWN_ARGUMENTS);
args::Parser args_parser_handle_all (args::ParserMode::HANDLE_ALL);
// add identical options
args_parser_skip_unknown.SetOpt<std::string>({"-s" , "--string"}, args::ArgType::ARGS_OPTIONAL, "String description");
args_parser_handle_all.SetOpt<std::string> ({"-s" , "--string"}, args::ArgType::ARGS_OPTIONAL, "String description");
try
{
args_parser_skip_unknown.Parse(argc, argv);
}
catch(const args::ParseError &e)
{
// not expected exception for unknown argument
std::cout << "Parse error (mode == args::ParserMode::IGNORE_UNKNOWN_ARGUMENTS): " << e.what() << std::endl;
}
catch(const std::exception &e)
{
// handle etc.
std::cout << "Error: " << e.what() << std::endl;
}
try
{
args_parser_handle_all.Parse(argc, argv);
}
catch(const args::ParseError &e)
{
// expected exception for unknown argument
std::cout << "Parse error (mode == args::ParserMode::HANDLE_ALL): " << e.what() << std::endl;
}
catch(const std::exception &e)
{
// handle etc.
std::cout << "Error: " << e.what() << std::endl;
}
return 0;
}