Skip to content
ZhreShold edited this page Sep 16, 2015 · 7 revisions

Start with an argument parser

// test.cpp
#include "zupply.hpp"
zz::cfg::argParser parser;

add option for help information

parser.add_opt_help('h', "help"); // use -h or --help

add version info

parser.add_opt_version('v', "version", "0.1"); // use -v or --version

add a bool flag

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

add simple value

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
Clone this wiki locally