-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (48 loc) · 1.52 KB
/
main.cpp
File metadata and controls
67 lines (48 loc) · 1.52 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
/*
Main test file for ArgParser project.
24/10/2020, Jack Shendrikov
*/
#include "ArgParser.h"
#include <iostream>
int main(int argc, char** argv) {
ArgParser argparse;
argparse.setArgument("h", "help", "See Help.", false);
argparse.setArgument("v", "version", "Print version information.", false);
argparse.setArgument("n", "number", "Print number, any number.", true);
argparse.setArgument("l", "list", "Print list content.", true);
argparse.setArgument("", "elf", "Elves only come in long (tall) form, there are no short elves.", false);
argparse.setArgument("d", "", "D is for dwarfs. They are only in short form.", false);
argparse.setDescription("Test for ArgParser project.");
argparse.setUsage("./main_test <options>");
if (!argparse.parseArguments(argc, argv)) {
cerr << "Couldn't parse arguments..." << endl;
return 1;
}
cout << "Number of flags found: " << argparse.flagCount() << endl;
if (argparse.exists("help")) {
argparse.printHelp();
cout << "Arg: help" << endl;
}
if (argparse.exists("version")) {
cout << "Arg: version" << endl;
}
if (argparse.exists("elf")) {
cout << "Arg: elf" << endl;
}
if (argparse.exists("d")) {
cout << "Arg: dwarf" << endl;
}
string number;
if (argparse.getFlag("number", number)) {
cout << "Arg: number " << number << endl;
}
string list;
if (argparse.getFlag("list", list)) {
cout << "Arg: list " << list << endl;
}
string textarg;
if (argparse.getTextArgument(0, textarg)) {
cout << "Got text argument: " << textarg << endl;
}
return 0;
}