-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
50 lines (39 loc) · 1.76 KB
/
main.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
50
#include <iostream>
#include <fstream>
#include <string>
#include <sys/stat.h>
#include <filesystem>
#include "argparser.h"
typedef argparser::__type Type;
std::vector <Type> args_types = {
Type("-ta", "--typical-argument", "Some typical argument"),
Type("-ata", "--another-typical-argument", "Another typical argument"),
Type("-siva", "--some-integer-value-argument", "Some argument with an integer value"),
Type("-eba", "--example-of-binary-argument", "An example of a binary argument", true)
};
int main(int argc, char *argv[]) {
std::ios_base::sync_with_stdio(false);
argparser::argparser parser;
for(int i = 0; i < args_types.size(); ++i) {
parser.addArgHandler(args_types[i]);
}
parser.parse_args(argc, argv);
std::cerr << "Args: " << std::endl;
for(auto el: parser.args) {
std::cerr << el.first << ": " << el.second << std::endl;
} std::cerr << std::endl << "---------" << std::endl << std::endl;
try {
std::string typical_argument = parser.handle_argument("--typical-argument");
std::string another_typical_argument = parser.handle_argument("--another-typical-argument", "Some default value");
std::string binary_argument = parser.handle_argument("--example-of-binary-argument");
int integer_value = std::stoi(parser.handle_argument("--some-integer-value-argument"));
std::cerr << "Typical argument: " << typical_argument << std::endl;
std::cerr << "Another typical argument: " << another_typical_argument << std::endl;
std::cerr << "Binary argument: " << binary_argument << std::endl;
std::cerr << "Integer: " << integer_value << std::endl;
} catch(std::string e) {
std::cerr << e << std::endl;
return 0;
}
return 0;
}