mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-09 20:33:39 -04:00
fix to handle optional unlabeled args
This commit is contained in:
parent
7730bf0d62
commit
ce60f03fd3
@ -19,6 +19,7 @@ libtclapinclude_HEADERS = \
|
|||||||
CmdLineOutput.h \
|
CmdLineOutput.h \
|
||||||
StdOutput.h \
|
StdOutput.h \
|
||||||
DocBookOutput.h \
|
DocBookOutput.h \
|
||||||
|
OptionalUnlabeledTracker.h \
|
||||||
Constraint.h \
|
Constraint.h \
|
||||||
ValuesConstraint.h
|
ValuesConstraint.h
|
||||||
|
|
||||||
|
62
include/tclap/OptionalUnlabeledTracker.h
Normal file
62
include/tclap/OptionalUnlabeledTracker.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
*
|
||||||
|
* file: OptionalUnlabeledTracker.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005, Michael E. Smoot .
|
||||||
|
* All rights reverved.
|
||||||
|
*
|
||||||
|
* See the file COPYING in the top directory of this distribution for
|
||||||
|
* more information.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H
|
||||||
|
#define TCLAP_OPTIONAL_UNLABELED_TRACKER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace TCLAP {
|
||||||
|
|
||||||
|
class OptionalUnlabeledTracker
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static void check( bool req, const std::string& argName );
|
||||||
|
|
||||||
|
static void gotOptional() { alreadyOptionalRef() = true; }
|
||||||
|
|
||||||
|
static bool& alreadyOptional() { return alreadyOptionalRef(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static bool& alreadyOptionalRef() { static bool ct = false; return ct; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void OptionalUnlabeledTracker::check( bool req, const std::string& argName )
|
||||||
|
{
|
||||||
|
if ( OptionalUnlabeledTracker::alreadyOptional() )
|
||||||
|
throw( SpecificationException(
|
||||||
|
"You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg",
|
||||||
|
argName ) );
|
||||||
|
|
||||||
|
if ( !req )
|
||||||
|
OptionalUnlabeledTracker::gotOptional();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace TCLAP
|
||||||
|
|
||||||
|
#endif
|
@ -27,6 +27,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <tclap/MultiArg.h>
|
#include <tclap/MultiArg.h>
|
||||||
|
#include <tclap/OptionalUnlabeledTracker.h>
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP {
|
||||||
|
|
||||||
@ -57,6 +58,8 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
* identification, not as a long flag.
|
* identification, not as a long flag.
|
||||||
* \param desc - A description of what the argument is for or
|
* \param desc - A description of what the argument is for or
|
||||||
* does.
|
* does.
|
||||||
|
* \param req - Whether the argument is required on the command
|
||||||
|
* line.
|
||||||
* \param typeDesc - A short, human readable description of the
|
* \param typeDesc - A short, human readable description of the
|
||||||
* type that this object expects. This is used in the generation
|
* type that this object expects. This is used in the generation
|
||||||
* of the USAGE statement. The goal is to be helpful to the end user
|
* of the USAGE statement. The goal is to be helpful to the end user
|
||||||
@ -68,6 +71,7 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
*/
|
*/
|
||||||
UnlabeledMultiArg( const std::string& name,
|
UnlabeledMultiArg( const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
const std::string& typeDesc,
|
const std::string& typeDesc,
|
||||||
bool ignoreable = false,
|
bool ignoreable = false,
|
||||||
Visitor* v = NULL );
|
Visitor* v = NULL );
|
||||||
@ -77,6 +81,8 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
* identification, not as a long flag.
|
* identification, not as a long flag.
|
||||||
* \param desc - A description of what the argument is for or
|
* \param desc - A description of what the argument is for or
|
||||||
* does.
|
* does.
|
||||||
|
* \param req - Whether the argument is required on the command
|
||||||
|
* line.
|
||||||
* \param typeDesc - A short, human readable description of the
|
* \param typeDesc - A short, human readable description of the
|
||||||
* type that this object expects. This is used in the generation
|
* type that this object expects. This is used in the generation
|
||||||
* of the USAGE statement. The goal is to be helpful to the end user
|
* of the USAGE statement. The goal is to be helpful to the end user
|
||||||
@ -89,6 +95,7 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
*/
|
*/
|
||||||
UnlabeledMultiArg( const std::string& name,
|
UnlabeledMultiArg( const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
const std::string& typeDesc,
|
const std::string& typeDesc,
|
||||||
CmdLineInterface& parser,
|
CmdLineInterface& parser,
|
||||||
bool ignoreable = false,
|
bool ignoreable = false,
|
||||||
@ -100,6 +107,8 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
* identification, not as a long flag.
|
* identification, not as a long flag.
|
||||||
* \param desc - A description of what the argument is for or
|
* \param desc - A description of what the argument is for or
|
||||||
* does.
|
* does.
|
||||||
|
* \param req - Whether the argument is required on the command
|
||||||
|
* line.
|
||||||
* \param constraint - A pointer to a Constraint object used
|
* \param constraint - A pointer to a Constraint object used
|
||||||
* to constrain this Arg.
|
* to constrain this Arg.
|
||||||
* \param ignoreable - Whether or not this argument can be ignored
|
* \param ignoreable - Whether or not this argument can be ignored
|
||||||
@ -109,6 +118,7 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
*/
|
*/
|
||||||
UnlabeledMultiArg( const std::string& name,
|
UnlabeledMultiArg( const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
Constraint<T>* constraint,
|
Constraint<T>* constraint,
|
||||||
bool ignoreable = false,
|
bool ignoreable = false,
|
||||||
Visitor* v = NULL );
|
Visitor* v = NULL );
|
||||||
@ -119,6 +129,8 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
* identification, not as a long flag.
|
* identification, not as a long flag.
|
||||||
* \param desc - A description of what the argument is for or
|
* \param desc - A description of what the argument is for or
|
||||||
* does.
|
* does.
|
||||||
|
* \param req - Whether the argument is required on the command
|
||||||
|
* line.
|
||||||
* \param constraint - A pointer to a Constraint object used
|
* \param constraint - A pointer to a Constraint object used
|
||||||
* to constrain this Arg.
|
* to constrain this Arg.
|
||||||
* \param parser - A CmdLine parser object to add this Arg to
|
* \param parser - A CmdLine parser object to add this Arg to
|
||||||
@ -129,6 +141,7 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
*/
|
*/
|
||||||
UnlabeledMultiArg( const std::string& name,
|
UnlabeledMultiArg( const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
Constraint<T>* constraint,
|
Constraint<T>* constraint,
|
||||||
CmdLineInterface& parser,
|
CmdLineInterface& parser,
|
||||||
bool ignoreable = false,
|
bool ignoreable = false,
|
||||||
@ -172,24 +185,28 @@ class UnlabeledMultiArg : public MultiArg<T>
|
|||||||
template<class T>
|
template<class T>
|
||||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
const std::string& typeDesc,
|
const std::string& typeDesc,
|
||||||
bool ignoreable,
|
bool ignoreable,
|
||||||
Visitor* v)
|
Visitor* v)
|
||||||
: MultiArg<T>("", name, desc, false, typeDesc, v)
|
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
OptionalUnlabeledTracker::check(true, toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
const std::string& typeDesc,
|
const std::string& typeDesc,
|
||||||
CmdLineInterface& parser,
|
CmdLineInterface& parser,
|
||||||
bool ignoreable,
|
bool ignoreable,
|
||||||
Visitor* v)
|
Visitor* v)
|
||||||
: MultiArg<T>("", name, desc, false, typeDesc, v)
|
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
OptionalUnlabeledTracker::check(true, toString());
|
||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,24 +214,28 @@ UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
|||||||
template<class T>
|
template<class T>
|
||||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
Constraint<T>* constraint,
|
Constraint<T>* constraint,
|
||||||
bool ignoreable,
|
bool ignoreable,
|
||||||
Visitor* v)
|
Visitor* v)
|
||||||
: MultiArg<T>("", name, desc, false, constraint, v)
|
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
OptionalUnlabeledTracker::check(true, toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||||
const std::string& desc,
|
const std::string& desc,
|
||||||
|
bool req,
|
||||||
Constraint<T>* constraint,
|
Constraint<T>* constraint,
|
||||||
CmdLineInterface& parser,
|
CmdLineInterface& parser,
|
||||||
bool ignoreable,
|
bool ignoreable,
|
||||||
Visitor* v)
|
Visitor* v)
|
||||||
: MultiArg<T>("", name, desc, false, constraint, v)
|
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
OptionalUnlabeledTracker::check(true, toString());
|
||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <tclap/ValueArg.h>
|
#include <tclap/ValueArg.h>
|
||||||
|
#include <tclap/OptionalUnlabeledTracker.h>
|
||||||
|
|
||||||
|
|
||||||
namespace TCLAP {
|
namespace TCLAP {
|
||||||
|
|
||||||
@ -200,6 +202,7 @@ class UnlabeledValueArg : public ValueArg<T>
|
|||||||
* \param argList - The list to add this to.
|
* \param argList - The list to add this to.
|
||||||
*/
|
*/
|
||||||
virtual void addToList( std::list<Arg*>& argList ) const;
|
virtual void addToList( std::list<Arg*>& argList ) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,6 +219,9 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
|||||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
|
||||||
|
OptionalUnlabeledTracker::check(req, toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -230,6 +236,7 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
|||||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
OptionalUnlabeledTracker::check(req, toString());
|
||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,6 +254,7 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
|||||||
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
OptionalUnlabeledTracker::check(req, toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -261,6 +269,7 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
|||||||
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
||||||
{
|
{
|
||||||
_ignoreable = ignoreable;
|
_ignoreable = ignoreable;
|
||||||
|
OptionalUnlabeledTracker::check(req, toString());
|
||||||
parser.add( this );
|
parser.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user