1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/demo/arg_parser_demo.cc Sat Mar 03 12:05:05 2007 +0000
1.3 @@ -0,0 +1,53 @@
1.4 +#include <lemon/arg_parser.h>
1.5 +
1.6 +using namespace lemon;
1.7 +int main(int argc, char **argv)
1.8 +{
1.9 + ArgParser ap(argc,argv);
1.10 + int i;
1.11 + std::string s;
1.12 + double d;
1.13 + bool b,sil;
1.14 + bool g1,g2,g3;
1.15 + ap.option("n", "an integer input", i, true)
1.16 + .option("val", "a double input", d)
1.17 + .synonym("vals","val")
1.18 + .option("name", "a string input", s)
1.19 + .option("f", "a switch", b)
1.20 + .option("nohelp", "", sil)
1.21 + .option("gra","Choise A",g1)
1.22 + .option("grb","Choise B",g2)
1.23 + .option("grc","Choise C",g3)
1.24 + .optionGroup("gr","gra")
1.25 + .optionGroup("gr","grb")
1.26 + .optionGroup("gr","grc")
1.27 + .mandatoryGroup("gr")
1.28 + .onlyOneGroup("gr")
1.29 + .other("infile","The input file")
1.30 + .other("...");
1.31 +
1.32 + ap.parse();
1.33 +
1.34 + std::cout << "Parameters of '" << ap.commandName() << "':\n";
1.35 +
1.36 + if(ap.given("n")) std::cout << " Value of -n: " << i << std::endl;
1.37 + if(ap.given("val")) std::cout << " Value of -val: " << d << std::endl;
1.38 + if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl;
1.39 + if(ap.given("f")) std::cout << " -f is given\n";
1.40 + if(ap.given("nohelp")) std::cout << " Value of -nohelp: " << sil << std::endl;
1.41 +
1.42 + switch(ap.files().size()) {
1.43 + case 0:
1.44 + std::cout << " No file argument was given.\n";
1.45 + break;
1.46 + case 1:
1.47 + std::cout << " 1 file argument was given. It is:\n";
1.48 + break;
1.49 + default:
1.50 + std::cout << " "
1.51 + << ap.files().size() << " file arguments were given. They are:\n";
1.52 + }
1.53 + for(unsigned int i=0;i<ap.files().size();++i)
1.54 + std::cout << " '" << ap.files()[i] << "'\n";
1.55 +
1.56 +}