-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.cpp
More file actions
72 lines (60 loc) · 2.1 KB
/
errors.cpp
File metadata and controls
72 lines (60 loc) · 2.1 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdexcept>
#include <iostream>
#include <vector>
#include <map>
#include "../args.h"
using std::vector;
int main(int argc, const char** argv) {
auto b = false;
auto num = 0;
auto str = ""s;
auto v = std::vector<int>{};
auto mapk = std::map<int, std::string>{};
auto mapv = std::map<std::string, int>{};
auto f = false;
auto p = args::parser{}
.option("--bool", &b)
.option("--num", &num)
.option("--str", &str)
.option("-v", &v)
.option("--mapk", &mapk)
.option("--mapv", &mapv)
.option("-f", &f);
p.command("cmd")
.option("--cbool", &b)
.option("--cnum", &num)
.option("--cstr", &str)
.option("-cv", &v)
.option("--cmapk", &mapk)
.option("--cmapv", &mapv)
.option("-cf", &f);
try {
p.parse(argc, argv);
} catch (const args::invalid_option& err) {
std::cout << err.what() << std::endl;
std::cout << ".option=\"" << err.option << "\"" << std::endl;
} catch (const args::invalid_command_option_value& err) {
std::cout << err.what() << std::endl;
std::cout << ".command=\"" << err.command << "\"" << std::endl;
std::cout << ".option=\"" << err.option << "\"" << std::endl;
std::cout << ".value=\"" << err.value << "\"" << std::endl;
} catch (const args::invalid_option_value& err) {
std::cout << err.what() << std::endl;
std::cout << ".option=\"" << err.option << "\"" << std::endl;
std::cout << ".value=\"" << err.value << "\"" << std::endl;
} catch (const args::invalid_command_arg_value& err) {
std::cout << err.what() << std::endl;
std::cout << ".command=\"" << err.command << "\"" << std::endl;
std::cout << ".arg=\"" << err.arg << "\"" << std::endl;
std::cout << ".value=\"" << err.value << "\"" << std::endl;
} catch (const args::invalid_arg_value& err) {
std::cout << err.what() << std::endl;
std::cout << ".arg=\"" << err.arg << "\"" << std::endl;
std::cout << ".value=\"" << err.value << "\"" << std::endl;
} catch (const args::unexpected_arg& err) {
std::cout << err.what() << std::endl;
std::cout << ".value=\"" << err.value << "\"" << std::endl;
} catch (const std::runtime_error& err) {
// base class for all parser errors
}
}