mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-09 20:33:39 -04:00
Added support for automatic addition to a CmdLine parser
This commit is contained in:
parent
35a072e0b6
commit
46fdfd07c3
74
src/Arg.cpp
74
src/Arg.cpp
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <tclap/Arg.h>
|
#include <tclap/Arg.h>
|
||||||
|
#include <tclap/CommandLine.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -35,24 +36,8 @@ const string Arg::flagStartString = "-";
|
|||||||
const string Arg::nameStartString = "--";
|
const string Arg::nameStartString = "--";
|
||||||
const string Arg::ignoreNameString = "ignore_rest";
|
const string Arg::ignoreNameString = "ignore_rest";
|
||||||
|
|
||||||
Arg::Arg( const string& flag,
|
void Arg::init()
|
||||||
const string& name,
|
{
|
||||||
const string& desc,
|
|
||||||
bool req,
|
|
||||||
bool valreq,
|
|
||||||
Visitor* v)
|
|
||||||
:
|
|
||||||
_flag(flag),
|
|
||||||
_name(name),
|
|
||||||
_description(desc),
|
|
||||||
_required(req),
|
|
||||||
_requireLabel("required"),
|
|
||||||
_valueRequired(valreq),
|
|
||||||
_alreadySet(false),
|
|
||||||
_visitor( v ),
|
|
||||||
_ignoreable(true),
|
|
||||||
_xorSet(false)
|
|
||||||
{
|
|
||||||
if ( _flag.length() > 1 )
|
if ( _flag.length() > 1 )
|
||||||
throw(ArgException("Argument flag can only be one character long",
|
throw(ArgException("Argument flag can only be one character long",
|
||||||
toString() ) );
|
toString() ) );
|
||||||
@ -73,9 +58,62 @@ Arg::Arg( const string& flag,
|
|||||||
Arg::flagStartString + "' or '" +
|
Arg::flagStartString + "' or '" +
|
||||||
Arg::nameStartString + "' or space.",
|
Arg::nameStartString + "' or space.",
|
||||||
toString() ) );
|
toString() ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Arg::Arg( const string& flag,
|
||||||
|
const string& name,
|
||||||
|
const string& desc,
|
||||||
|
bool req,
|
||||||
|
bool valreq,
|
||||||
|
Visitor* v)
|
||||||
|
:
|
||||||
|
_flag(flag),
|
||||||
|
_name(name),
|
||||||
|
_description(desc),
|
||||||
|
_required(req),
|
||||||
|
_requireLabel("required"),
|
||||||
|
_valueRequired(valreq),
|
||||||
|
_alreadySet(false),
|
||||||
|
_visitor( v ),
|
||||||
|
_ignoreable(true),
|
||||||
|
_xorSet(false)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
init(); //< initialize the object
|
||||||
|
} catch (ArgException ae) {
|
||||||
|
throw(ae); //< and forward any exceptions
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Arg::Arg(const std::string& flag,
|
||||||
|
const std::string& name,
|
||||||
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
|
bool valreq,
|
||||||
|
CmdLine &parser,
|
||||||
|
Visitor* v) :
|
||||||
|
_flag(flag),
|
||||||
|
_name(name),
|
||||||
|
_description(desc),
|
||||||
|
_required(req),
|
||||||
|
_requireLabel("required"),
|
||||||
|
_valueRequired(valreq),
|
||||||
|
_alreadySet(false),
|
||||||
|
_visitor( v ),
|
||||||
|
_ignoreable(true),
|
||||||
|
_xorSet(false)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
init(); //< initialize the object
|
||||||
|
} catch (ArgException ae) {
|
||||||
|
throw(ae); //< and forward any exceptions
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add to the parser, what about exceptions
|
||||||
|
parser.add(*this);
|
||||||
|
}
|
||||||
|
|
||||||
Arg::Arg()
|
Arg::Arg()
|
||||||
:
|
:
|
||||||
_flag(""),
|
_flag(""),
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <tclap/SwitchArg.h>
|
#include <tclap/SwitchArg.h>
|
||||||
|
#include <tclap/CommandLine.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -35,6 +36,18 @@ SwitchArg::SwitchArg(const string& flag,
|
|||||||
_value( _default )
|
_value( _default )
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
|
SwitchArg::SwitchArg(const string& flag,
|
||||||
|
const string& name,
|
||||||
|
const string& desc,
|
||||||
|
bool _default,
|
||||||
|
CmdLine &parser,
|
||||||
|
Visitor* v )
|
||||||
|
: Arg(flag, name, desc, false, false, v),
|
||||||
|
_value( _default )
|
||||||
|
{
|
||||||
|
parser.add(*this);
|
||||||
|
}
|
||||||
|
|
||||||
SwitchArg::~SwitchArg() { };
|
SwitchArg::~SwitchArg() { };
|
||||||
|
|
||||||
bool SwitchArg::getValue() { return _value; };
|
bool SwitchArg::getValue() { return _value; };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user