-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.cpp
90 lines (70 loc) · 2.36 KB
/
demo.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include "argh.h"
int demo_easy(int argc, char const* argv[])
{
std::cout << "::: Babytown Frolics! :::" << std::endl;
bool help;
int mynumber;
Argh argh;
argh.addFlag(help, "--help");
argh.addOption<int>(mynumber, 123, "--mynumber");
argh.parse(argc, argv);
if (help) {
std::cout << argh.getUsage() << std::endl;
}
std::cout << "mynumber = " << mynumber << std::endl;
std::cout << std::endl;
return EXIT_SUCCESS;
}
int demo_medium(int argc, char const* argv[])
{
std::cout << "::: I've been around the block! :::" << std::endl;
bool help;
bool boolValue;
float floatValue;
int intValue;
std::string stringValue;
std::vector<float> multiValue;
std::vector<std::string> multiStringValue;
Argh argh;
argh.addFlag(help, "--help", "Display this message");
argh.addOption<bool>(boolValue, false, "--boolvalue", "True? False?");
argh.addOption<float>(floatValue, 3.14f, "--floatvalue", "Get real");
argh.addOption<int>(intValue, 123, "--intvalue", "Optional description");
argh.addOption<std::string>(stringValue, "It's a default", "--stringvalue");
argh.addMultiOption<float>(multiValue, "1.f,2.f,3.f", "--multivalue", "See? Look up. Told you it was optional!");
argh.addMultiOption<std::string>(multiStringValue, "one,two,three", "--multistringvalue", "It's so easy!");
argh.load("argh.opts");
argh.parse(argc, argv);
std::cout << argh.getUsage() << std::endl;
if (argh.isParsed("--multivalue")) {
std::cout << "multiValue changed from the default to:" << std::endl;
for (auto v : multiValue) {
std::cout << v << std::endl;
}
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
int demo_hard(int argc, char const* argv[])
{
std::cout << "::: Futurejet fighter pilot! :::" << std::endl;
Argh argh('|');
std::vector<std::string> complex;
argh.addMultiOption<std::string>(complex, "one|two", "--complex");
argh.parse(argc, argv);
std::cout << argh.getUsage() << std::endl;
std::cout << "You so crazy. complex is:" << std::endl;
for (auto c : complex) {
std::cout << c << std::endl;
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
int main(int argc, char const* argv[])
{
demo_easy(argc, argv);
demo_medium(argc, argv);
demo_hard(argc, argv);
return EXIT_SUCCESS;
}