alpar@2389
|
1 |
#include <lemon/arg_parser.h>
|
alpar@2389
|
2 |
|
alpar@2389
|
3 |
using namespace lemon;
|
alpar@2389
|
4 |
int main(int argc, char **argv)
|
alpar@2389
|
5 |
{
|
alpar@2389
|
6 |
ArgParser ap(argc,argv);
|
alpar@2389
|
7 |
int i;
|
alpar@2389
|
8 |
std::string s;
|
alpar@2389
|
9 |
double d;
|
alpar@2389
|
10 |
bool b,sil;
|
alpar@2389
|
11 |
bool g1,g2,g3;
|
alpar@2389
|
12 |
ap.option("n", "an integer input", i, true)
|
alpar@2389
|
13 |
.option("val", "a double input", d)
|
alpar@2389
|
14 |
.synonym("vals","val")
|
alpar@2389
|
15 |
.option("name", "a string input", s)
|
alpar@2389
|
16 |
.option("f", "a switch", b)
|
alpar@2389
|
17 |
.option("nohelp", "", sil)
|
alpar@2389
|
18 |
.option("gra","Choise A",g1)
|
alpar@2389
|
19 |
.option("grb","Choise B",g2)
|
alpar@2389
|
20 |
.option("grc","Choise C",g3)
|
alpar@2389
|
21 |
.optionGroup("gr","gra")
|
alpar@2389
|
22 |
.optionGroup("gr","grb")
|
alpar@2389
|
23 |
.optionGroup("gr","grc")
|
alpar@2389
|
24 |
.mandatoryGroup("gr")
|
alpar@2389
|
25 |
.onlyOneGroup("gr")
|
alpar@2389
|
26 |
.other("infile","The input file")
|
alpar@2389
|
27 |
.other("...");
|
alpar@2389
|
28 |
|
alpar@2389
|
29 |
ap.parse();
|
alpar@2389
|
30 |
|
alpar@2389
|
31 |
std::cout << "Parameters of '" << ap.commandName() << "':\n";
|
alpar@2389
|
32 |
|
alpar@2389
|
33 |
if(ap.given("n")) std::cout << " Value of -n: " << i << std::endl;
|
alpar@2389
|
34 |
if(ap.given("val")) std::cout << " Value of -val: " << d << std::endl;
|
alpar@2389
|
35 |
if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl;
|
alpar@2389
|
36 |
if(ap.given("f")) std::cout << " -f is given\n";
|
alpar@2389
|
37 |
if(ap.given("nohelp")) std::cout << " Value of -nohelp: " << sil << std::endl;
|
alpar@2389
|
38 |
|
alpar@2389
|
39 |
switch(ap.files().size()) {
|
alpar@2389
|
40 |
case 0:
|
alpar@2389
|
41 |
std::cout << " No file argument was given.\n";
|
alpar@2389
|
42 |
break;
|
alpar@2389
|
43 |
case 1:
|
alpar@2389
|
44 |
std::cout << " 1 file argument was given. It is:\n";
|
alpar@2389
|
45 |
break;
|
alpar@2389
|
46 |
default:
|
alpar@2389
|
47 |
std::cout << " "
|
alpar@2389
|
48 |
<< ap.files().size() << " file arguments were given. They are:\n";
|
alpar@2389
|
49 |
}
|
alpar@2389
|
50 |
for(unsigned int i=0;i<ap.files().size();++i)
|
alpar@2389
|
51 |
std::cout << " '" << ap.files()[i] << "'\n";
|
alpar@2389
|
52 |
|
alpar@2389
|
53 |
}
|