-
Notifications
You must be signed in to change notification settings - Fork 12
Argument Parser
ZhreShold edited this page Sep 16, 2015
·
7 revisions
// test.cpp
#include "zupply.hpp"
zz::cfg::argParser parser;
parser.add_opt_help('h', "help"); // use -h or --help
parser.add_opt_version('v', "version", "0.1"); // use -v or --version
bool flag;
parser.add_opt_flag('f', "flag", "this is a flag option", &flag);
If you specify "-f" or "--flag" in arguments, the bool flag will be set to true, otherwise flag == false.
test -f --flag
int i;
parser.add_opt_value('i', "integer", i, -1, "set integer value of i", "INT").require();
double d;
parser.add_opt_value('d', "double", d, 0.0, "set double value of d", "DOUBLE");
// vector is also supported
std::vector<double> vd;
parser.add_opt_value(-1, "vector", vd, std::vector<double>(), "load a vector").set_max(4);
test -i 100 -d 0.1 --vector 0.1 1.2 2.3 3.4
####Print help information:
std::cout << parser.get_help() << std::endl;
Usage: test
version: 0.1
-h, --help print this help and exit
-v, --version print version and exit
-f, --flag this is a flag option
-i, --integer=INT set integer value of i(default: -1)
-d, --double=DOUBLE set double value of d(default: 0)
--vector load a vector
--custom custom option