new library for arguments - namespace mrw added; refs #6

This commit is contained in:
Marc Wäckerlin
2013-09-26 14:28:12 +00:00
parent a6b48ec7c4
commit fbe6874579
3 changed files with 485 additions and 421 deletions

View File

@@ -21,57 +21,66 @@ int main(int argc, char** argv) try {
// bind and evaluate options
#ifdef ARGS__OLD_PRE11_COMPILER
args::list options;
std::vector<std::shared_ptr<args::abstract_parameter> > params;
params.push_back(args::help());
params.push_back(args::exit());
options.push_back(args::declaration("h", "help", "show this help", params));
mrw::args::list options;
std::vector<std::shared_ptr<mrw::args::abstract_parameter> > params;
params.push_back(mrw::args::help());
params.push_back(mrw::args::exit());
options.push_back(mrw::args::declaration("h", "help", "show this help",
params));
params.clear();
params.push_back(args::param(r, "number"));
options.push_back(args::declaration("r", "repeat", "number of repetitions",
params));
params.push_back(mrw::args::param(r, "number"));
options.push_back(mrw::args::declaration("r", "repeat",
"number of repetitions",
params));
params.clear();
params.push_back(args::param(flag));
options.push_back(args::declaration("f", "flag", "check a flag", params));
params.push_back(mrw::args::param(flag));
options.push_back(mrw::args::declaration("f", "flag", "check a flag",
params));
params.clear();
params.push_back(args::param(txt, "text"));
options.push_back(args::declaration("t", "text", "pass a text", params));
params.push_back(mrw::args::param(txt, "text"));
options.push_back(mrw::args::declaration("t", "text", "pass a text", params));
params.clear();
params.push_back(args::param(x, "x"));
params.push_back(args::param(y, "y"));
options.push_back(args::declaration("c", "coord", "add some 2D coordinates",
params));
params.push_back(mrw::args::param(x, "x"));
params.push_back(mrw::args::param(y, "y"));
options.push_back(mrw::args::declaration("c", "coord",
"add some 2D coordinates",
params));
params.clear();
params.push_back(args::func(test_func));
options.push_back(args::declaration("", "test",
"call test_func, no shortcut", params));
args::init(argc, argv, "This is an example for argument processing.",
options);
params.push_back(mrw::args::func(test_func));
options.push_back(mrw::args::declaration("", "test",
"call test_func, no shortcut",
params));
mrw::args::parse(argc, argv, "This is an example for argument processing.",
options);
#else
args::init(argc, argv,
"This is an example for argument processing. If the description "
"is very long, it is automatically splitted over several lines "
"and indented on each new line. Arguments may have several "
"parameters. Help is generated automatically from the argument "
"declaration. The argument declaration contains long and short "
"options and a list of parameters.",
{
{"h", "help", "show this help", {args::help(), args::exit()}},
{"r", "repeat", "number of repetitions",
{args::param(r, "number")}},
{"f", "flag",
"check a flag; this is a boolean, so it is false by "
"default and true if the user specifies the flag on "
"the command line", {args::param(flag)}},
{"t", "text", "pass a text", {args::param(txt, "text")}},
{"c", "coord",
"add some 2D coordinates; this is an example on how "
"you can add more than one parameter",
{args::param(x, "x"), args::param(y, "y")}},
{"", "test", "call test_func, no shortcut",
{args::func(test_func)}},
},
"Returns a status of 0 on success and 1 on any error.");
mrw::args::parse(argc, argv,
"This is an example for argument processing. If the"
" description is very long, it is automatically splitted"
" over several lines and indented on each new line."
" Arguments may have several parameters. Help is"
" generated automatically from the argument declaration."
" The argument declaration contains long and short options"
" and a list of parameters.",
{
{"h", "help", "show this help",
{mrw::args::help(), mrw::args::exit()}},
{"r", "repeat", "number of repetitions",
{mrw::args::param(r, "number")}},
{"f", "flag",
"check a flag; this is a boolean, so it is false by "
"default and true if the user specifies the flag on "
"the command line", {mrw::args::param(flag)}},
{"t", "text", "pass a text",
{mrw::args::param(txt, "text")}},
{"c", "coord",
"add some 2D coordinates; this is an example on how "
"you can add more than one parameter",
{mrw::args::param(x, "x"),
mrw::args::param(y, "y")}},
{"", "test", "call test_func, no shortcut",
{mrw::args::func(test_func)}},
},
"Returns a status of 0 on success and 1 on any error.");
#endif
// show the result