diff options
Diffstat (limited to 'TCLAP/tclap/CmdLine.h')
-rw-r--r-- | TCLAP/tclap/CmdLine.h | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/TCLAP/tclap/CmdLine.h b/TCLAP/tclap/CmdLine.h index c91e656..dc49bae 100644 --- a/TCLAP/tclap/CmdLine.h +++ b/TCLAP/tclap/CmdLine.h @@ -183,6 +183,11 @@ private: */ bool _helpAndVersion; + /** + * Whether or not to ignore unmatched args. + */ + bool _ignoreUnmatched; + public: /** @@ -232,7 +237,7 @@ private: * add does not need to be called. * \param xors - List of Args to be added and xor'd. */ - void xorAdd( std::vector<Arg*>& xors ); + void xorAdd( const std::vector<Arg*>& xors ); /** * Parses the command line. @@ -313,6 +318,13 @@ private: */ void reset(); + /** + * Allows unmatched args to be ignored. By default false. + * + * @param ignore If true the cmdline will ignore any unmatched args + * and if false it will behave as normal. + */ + void ignoreUnmatched(const bool ignore); }; @@ -337,7 +349,8 @@ inline CmdLine::CmdLine(const std::string& m, _output(0), _handleExceptions(true), _userSetOutput(false), - _helpAndVersion(help) + _helpAndVersion(help), + _ignoreUnmatched(false) { _constructor(); } @@ -390,7 +403,7 @@ inline void CmdLine::_constructor() deleteOnExit(v); } -inline void CmdLine::xorAdd( std::vector<Arg*>& ors ) +inline void CmdLine::xorAdd( const std::vector<Arg*>& ors ) { _xorHandler.add( ors ); @@ -445,8 +458,14 @@ inline void CmdLine::parse(std::vector<std::string>& args) { bool shouldExit = false; int estat = 0; - try { + if (args.empty()) { + // https://sourceforge.net/p/tclap/bugs/30/ + throw CmdLineParseException("The args vector must not be empty, " + "the first entry should contain the " + "program's name."); + } + _progName = args.front(); args.erase(args.begin()); @@ -470,7 +489,7 @@ inline void CmdLine::parse(std::vector<std::string>& args) if ( !matched && _emptyCombined( args[i] ) ) matched = true; - if ( !matched && !Arg::ignoreRest() ) + if ( !matched && !Arg::ignoreRest() && !_ignoreUnmatched) throw(CmdLineParseException("Couldn't find match " "for argument", args[i])); @@ -623,6 +642,11 @@ inline void CmdLine::reset() _progName.clear(); } +inline void CmdLine::ignoreUnmatched(const bool ignore) +{ + _ignoreUnmatched = ignore; +} + /////////////////////////////////////////////////////////////////////////////// //End CmdLine.cpp /////////////////////////////////////////////////////////////////////////////// |