-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnested_alternatives.cpp
More file actions
81 lines (73 loc) · 2.61 KB
/
Copy pathnested_alternatives.cpp
File metadata and controls
81 lines (73 loc) · 2.61 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*****************************************************************************
*
* demo program - part of CLIPP (command line interfaces for modern C++)
*
* released under MIT license
*
* (c) 2017-2018 André Müller; foss@andremueller-online.de
*
*****************************************************************************/
#include <iostream>
#include <string>
#include <vector>
#include <clipp.h>
int main(int argc, char* argv[])
{
using namespace clipp;
using std::cout;
bool verbose = false;
bool init = true;
int bsize = 1024;
enum class mode {help, build, query};
bool add = false;
enum class fmt {plain, json, xml};
mode selected;
std::vector<std::string> infiles;
std::string outfile;
std::string outfmt;
auto cli = (
command("help")
| ( command("build").set(selected,mode::help),
( command("new").set(selected,mode::build).set(add,false)
| command("add").set(selected,mode::build).set(add,true) ),
values("file", infiles),
option("-v", "--verbose").set(verbose) % "print detailed report",
option("-b", "--buffer") & opt_value(
"size="+std::to_string(bsize), bsize) % "sets buffer size in KiByte",
( option("--init").set(init)
| option("--no-init").set(init,false) ) % "do or don't initialize"
)
| ( command("query").set(selected,mode::query),
value("infile", infiles),
required("-o", "--out") & value("outfile", outfile),
option("-f", "--out-format") % "determine output format"
& value("format",outfmt)
)
);
if(parse(argc, argv, cli)) {
switch(selected) {
default:
case mode::help:
cout << make_man_page(cli, argv[0]) << '\n'; return 0;
case mode::build:
if(add)
cout << "adding to database\n";
else
cout << "building new database\n";
cout << "buffer size is " << bsize << '\n';
if(init) cout << "showing detailed information\n";
break;
case mode::query:
cout << "query database\n";
cout << "output to " << outfile << " in format " << outfmt << '\n';
break;
}
cout << "input files:";
for(const auto& f : infiles) cout << ' ' << f;
cout << "\n";
if(verbose) cout << "showing detailed information\n";
}
else {
cout << usage_lines(cli, argv[0]) << '\n';
}
}