added --version to arguments; refs #7
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
// 1 2 3 4 5 6 7 8
|
// 1 2 3 4 5 6 7 8
|
||||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||||
#ifndef __MRW__
|
#ifndef __MRW_ARGS__
|
||||||
#define __MRW__
|
#define __MRW_ARGS__
|
||||||
|
|
||||||
#include <mrw/checkcxx11.hxx>
|
#include <mrw/checkcxx11.hxx>
|
||||||
#include <mrw/iomanip.hxx>
|
#include <mrw/iomanip.hxx>
|
||||||
@@ -26,6 +26,10 @@
|
|||||||
@refs MRW__OLD_PRE11_COMPILER is set.
|
@refs MRW__OLD_PRE11_COMPILER is set.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Add version information for @c what and @c ident
|
||||||
|
const std::string MRW_IDENT("$Id: " PACKAGENAME "-" PACKAGEVERSION " $");
|
||||||
|
const std::string MRW_WHAT("#(@)" PACKAGENAME "-" PACKAGEVERSION);
|
||||||
|
|
||||||
namespace mrw {
|
namespace mrw {
|
||||||
/// Cool and easy evaluation of commandline arguments in C++11.
|
/// Cool and easy evaluation of commandline arguments in C++11.
|
||||||
/** Evaluating command line arguments is extremely easy with this library:
|
/** Evaluating command line arguments is extremely easy with this library:
|
||||||
@@ -44,6 +48,7 @@ namespace mrw {
|
|||||||
args::parse(argc, argv, "This is an example for argument processing.",
|
args::parse(argc, argv, "This is an example for argument processing.",
|
||||||
{
|
{
|
||||||
{"h", "help", "show this help", {args::help(), args::exit()}},
|
{"h", "help", "show this help", {args::help(), args::exit()}},
|
||||||
|
{"v", "version", "show version", {args::version(), args::exit()}},
|
||||||
{"r", "repeat", "number of repetitions",
|
{"r", "repeat", "number of repetitions",
|
||||||
{args::param(r, "number")}},
|
{args::param(r, "number")}},
|
||||||
{"f", "flag", "check a flag", {args::param(flag)}},
|
{"f", "flag", "check a flag", {args::param(flag)}},
|
||||||
@@ -332,6 +337,26 @@ namespace mrw {
|
|||||||
std::cout<<std::endl;
|
std::cout<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// @return version information
|
||||||
|
std::string version_text() {
|
||||||
|
# ifdef PACKAGEVERSION
|
||||||
|
# ifdef PACKAGENAME
|
||||||
|
std::string v(": " PACKAGENAME "-" PACKAGEVERSION);
|
||||||
|
# else
|
||||||
|
std::string v("-" PACKAGEVERSION);
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# ifdef PACKAGENAME
|
||||||
|
std::string v(": " PACKAGENAME);
|
||||||
|
# else
|
||||||
|
std::string v;
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
return filename() + v;
|
||||||
|
}
|
||||||
|
void show_version() {
|
||||||
|
std::cout<<version_text()<<std::endl;
|
||||||
|
}
|
||||||
void help_no_arg() {
|
void help_no_arg() {
|
||||||
show_help();
|
show_help();
|
||||||
}
|
}
|
||||||
@@ -344,9 +369,32 @@ namespace mrw {
|
|||||||
param_ptr help() {
|
param_ptr help() {
|
||||||
return func(args::help_no_arg);
|
return func(args::help_no_arg);
|
||||||
}
|
}
|
||||||
|
param_ptr version() {
|
||||||
|
return func(args::show_version);
|
||||||
|
}
|
||||||
param_ptr exit() {
|
param_ptr exit() {
|
||||||
return func(args::do_exit);
|
return func(args::do_exit);
|
||||||
}
|
}
|
||||||
|
/// Sets up an argument list containing help and version.
|
||||||
|
list defaults() {
|
||||||
|
#ifdef MRW__OLD_PRE11_COMPILER
|
||||||
|
list res;
|
||||||
|
decl::param_list h;
|
||||||
|
h.push_back(help());
|
||||||
|
h.push_back(exit());
|
||||||
|
decl::param_list v;
|
||||||
|
v.push_back(version());
|
||||||
|
v.push_back(exit());
|
||||||
|
res.push_back(decl("h", "help", "show help", h));
|
||||||
|
res.push_back(decl("v", "version", "show version", v));
|
||||||
|
return res;
|
||||||
|
#else // New C++ standard C++11 is great:
|
||||||
|
return list({
|
||||||
|
{"h", "help", "show help", {help(), exit()}},
|
||||||
|
{"v", "version", "show version", {version(), exit()}}
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user