arg  1.2
a C++ command-line parser
arg_ex2.cc

An exmaple with sub-parser

#include <arg.hh>
using namespace arg;
int main(int argc, char **argv)
{
Parser p;
auto sp = std::make_shared<SubParser>();
int va1 = 0;
sp->add_opt("param1").stow(va1)
.help("parameter 1")
.show_default();
double va2 = 1.0;
sp->add_opt("param2").stow(va2)
.help("parameter 2")
.show_default();
int op;
sp->add_opt("opt1").set(& op, 1)
.help("perform op 1");
sp->add_opt("opt2").set(& op, 2)
.help("perform op 2");
sp->add_opt_help();
p.add_opt('o', "options").store(sp);
p.add_opt_help();
p.parse(argc, argv);
return 0;
}
arg::Parser
The command-line parser.
Definition: arg.hh:129
arg::Parser::add_opt
Option & add_opt(int key, std::string const &name="", bool hide=false)
add an Option
Definition: arg.cc:268
arg::Parser::parse
void parse(int argc, char *argv[], bool ignore_unknown=false)
perform command-line parsing
Definition: arg.cc:292
arg
arg::Option::store
Option & store(std::shared_ptr< Value > ptr=0)
store value to "* ptr", the Value will be released by the Option
Definition: arg.cc:57
arg.hh
Header file for arg library.