-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleMainSimple.cpp
41 lines (33 loc) · 1.23 KB
/
exampleMainSimple.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
#include <iostream>
#include "include/argvParser.h"
using namespace std;
/**
* argument that has additional parameter
*/
int printCallBack(int index, char **buff) {
index++;
cout << "print : " << buff[index] << endl;
return index; // +1 because one further argument has been used
}
int main(int argvs, char **argv) {
// define program description
argvParser *p = new argvParser("Simple example","This application intends to be an example ");
// define program arguments
// lambda expression
p->addArg("-t", "--test", "simple lambda expression", [] { cout << "got test" << endl; })->addAdditionalHelp(
"type \"help -t to get this info \"");
// lambda expression
function<int(int, char **)> callBack = [](int i, char **buff) {
i++;
cout << "extended lambda with parameter : \"" << buff[i] << "\"" << endl;
return i;
};
p->addArg("-x", "--xx", "lambda expression argument", callBack)->numberOfParameter(1);
// callBack function
p->addArg("-o", "--open", "example to complete a file/dir", printCallBack)->numberOfParameter(1);
// check if all arguments are valid
if (!p->analyseArgv(argvs, argv)) {
p->printHelpMessage(true);
}
return 0;
}