-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_basic.cc
More file actions
42 lines (36 loc) · 1.33 KB
/
example_basic.cc
File metadata and controls
42 lines (36 loc) · 1.33 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
#include <iostream>
#include "options_parser/options_parser.h"
int main(int argc, char* argv[]) {
int vi;
std::string vs;
double vd;
options_parser::Parser app("usage and info", "further info ...");
app.add_parser(options_parser::parser()); // add default global parser
app.add_help();
app.add_option("--int NUM", &vi, "assigned int value");
app.add_option("--str STRING", &vs, "assigned string value");
app.add_option(
"--func <int-arg> <string-arg> <double-arg>",
[&](int i, std::string s, double d) {
vi = i;
vs = s;
vd = d;
},
"call the function over arguments, assign vi, vs, and vd at once.");
app.add_option(
"--config-file FILE",
options_parser::value().bind(&options_parser::config_file).ignore_value(),
"load config file, which just contains command arguments");
app.add_option(
"--verbose-config-file FILE",
options_parser::value().bind(&options_parser::config_file).apply([&](
std::string filename) {
std::cerr << "loaded config file " << filename << std::endl;
}),
"load config file and print");
app.parse(argc, argv).check_print(); // if has a error, print and exit
std::cerr << "vi " << vi << std::endl;
std::cerr << "vs " << vs << std::endl;
std::cerr << "vd " << vd << std::endl;
return 0;
}