-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-usage.cpp
49 lines (42 loc) · 1.3 KB
/
example-usage.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
#include <iostream>
#include "cclap/cclap.h"
// Chose to provide mandatory arguments first, check for correct order
int main() {
// Example command line argument string
int argc = 12;
const char *argv[] = {
"/home/adrian/repos/src/cclap/build/bin/cclap",
"required-arg1",
"required-arg2",
"-i",
"input_file1.txt",
"input_file2.txt",
"-o",
"outfile.txt",
"--single-switch",
"-s",
"--multi-switch-next",
"-src"
};
cclap::ArgParser ap(argc, (char **)argv);
const cclap::ArgName& program_name = ap.program_name();
// Retrieve the arguments
const cclap::ArgVector& arguments = ap.args();
const cclap::NamedPairVector& flags = ap.flags();
const cclap::ArgVector& switches = ap.switches();
std::cout << program_name << " ";
// Printing all the arguments, demo on how to access each one
for (auto arg: arguments) {
std::cout << arg << " ";
}
for (auto flag: flags) {
std::cout << "-" << flag.first << " ";
for (auto value: flag.second) {
std::cout << value << " ";
}
}
for (auto s: switches) {
std::cout << "-" << s << " ";
}
std::cout << std::endl;
}