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