-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (55 loc) · 2.66 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "ArgParser.h"
#include <iostream>
#include <list>
#include <vector>
int main(int argc, const char** argv)
{
bool flag = true;
std::string outfilename = "output.txt";
size_t size = 256;
float x = 0;
int n = 1, m = 0;
arg::Parser<std::string, true> parser(
"A configurable application\n"
"Author: Gabor Borbely, Contact: [email protected]\n"
"Very long text will be sliced into 'width' long chunks. But a manual '\\n' will produce a new-line, too.", // header
{"-h", "--help"} /*help options*/,
std::cout, std::cerr, /*you have to specify the output streams! */
"So Long, and Thanks for All the Fish!" /*optional footer*/,
75 /*optional width*/);
std::list<int> c1 = { 1, 2, 4, 8, 16 };
parser.AddArg(n, { "-n" }, "a number\nthe default value should match the choices, since the argument is optional", "", c1);
parser.AddArg(m, { }, "an other number\nIf the argument is positional, then the default value doesn't have to match the choices, because the check will be done when the argument will be provided", "", c1);
parser.AddArg(outfilename, {"-o", "--output"}, "insert explanation here", "string");
// explicit template parameter specification
parser.AddArg<std::string, std::initializer_list<std::string>, arg::list>(outfilename, { }, "positional string", "string",
{ "a", "b", "c", "d", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p" });
parser.AddArg(x, {}, "a real number, user must provide it");
{
std::vector<std::string> xflags = { "-x", "--float" };
parser.AddArg(x, xflags, "a float number", "", -10.f, 10.f);
}
parser.AddArg(size, { "-s", "--size" }, "a size, which can be very big!\n"
"Due to unsigned type, '-1' reads as maximum positive value!");
parser.AddFlag(flag, { "-f", "--flag", "--set" });
parser.AddFlag(flag, { "-F", "--reset" }, "", true, "negate");
// parser.AddFlag(flag2, { }, "a positional flag is prohibited");
parser.AddArg(flag, { }, "you can make a positional flag like this", "logical");
parser.AddArg(flag, { "-b", "--bool" }, "this type of bool option is different from 'flag' and requires a value", "logical");
if (parser.Do(argc, argv))
{
std::cout << m << std::endl;
std::cout << outfilename << std::endl;
std::cout << x << std::endl;
std::cout << flag << std::endl;
std::cout << std::endl;
std::cout << n << std::endl;
std::cout << size << std::endl;
return 0;
}
else
{
std::cout << "Something failed!" << std::endl;
return 1;
}
}