diff --git a/include/tclap/Arg.h b/include/tclap/Arg.h index b3512bb..9d32bb9 100644 --- a/include/tclap/Arg.h +++ b/include/tclap/Arg.h @@ -125,6 +125,8 @@ class Arg */ bool _xorSet; + bool _acceptsMultipleValues; + /** * Performs the special handling described by the Vistitor. */ @@ -330,6 +332,7 @@ class Arg void setRequireLabel( const std::string& s ); virtual bool allowMore(); + virtual bool acceptsMultipleValues(); }; @@ -368,7 +371,8 @@ inline Arg::Arg(const std::string& flag, _alreadySet(false), _visitor( v ), _ignoreable(true), - _xorSet(false) + _xorSet(false), + _acceptsMultipleValues(false) { if ( _flag.length() > 1 ) throw(SpecificationException( @@ -567,6 +571,11 @@ inline bool Arg::allowMore() return false; } +inline bool Arg::acceptsMultipleValues() +{ + return _acceptsMultipleValues; +} + ////////////////////////////////////////////////////////////////////// //END Arg.cpp ////////////////////////////////////////////////////////////////////// diff --git a/include/tclap/DocBookOutput.h b/include/tclap/DocBookOutput.h index 5a4e4e6..c9d00bc 100644 --- a/include/tclap/DocBookOutput.h +++ b/include/tclap/DocBookOutput.h @@ -76,6 +76,10 @@ class DocBookOutput : public CmdLineOutput * \param x - What to replace r with. */ void substituteSpecialChars( std::string& s, char r, std::string& x ); + void removeChar( std::string& s, char r); + + void printShortArg(Arg* it); + void printLongArg(Arg* it); }; @@ -88,6 +92,7 @@ inline void DocBookOutput::usage(CmdLineInterface& _cmd ) { std::list argList = _cmd.getArgList(); std::string progName = _cmd.getProgramName(); + std::string version = _cmd.getVersion(); XorHandler xorHandler = _cmd.getXorHandler(); std::vector< std::vector > xorList = xorHandler.getXorList(); @@ -97,39 +102,88 @@ inline void DocBookOutput::usage(CmdLineInterface& _cmd ) std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl; std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << progName << std::endl; + std::cout << "" << std::endl; + std::cout << "1" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << progName << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; std::cout << "" << progName << "" << std::endl; - std::string lt = "<"; - std::string gt = ">"; - // xor for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) { - std::cout << "" << std::endl; + std::cout << "" << std::endl; for ( ArgVectorIterator it = xorList[i].begin(); it != xorList[i].end(); it++ ) - { - std::string id = (*it)->shortID(); - substituteSpecialChars(id,'<',lt); - substituteSpecialChars(id,'>',gt); - std::cout << "" << id << "" << std::endl; - } + printShortArg((*it)); std::cout << "" << std::endl; } - + + // rest of args for (ArgListIterator it = argList.begin(); it != argList.end(); it++) if ( !xorHandler.contains( (*it) ) ) - { - std::string id = (*it)->shortID(); - substituteSpecialChars(id,'<',lt); - substituteSpecialChars(id,'>',gt); - std::cout << "" << id << "" << std::endl; - } + printShortArg((*it)); std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "Description" << std::endl; + std::cout << "" << std::endl; + std::cout << _cmd.getMessage() << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "Options" << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + // xor + for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) + { + std::cout << "" << std::endl; + size_t xlen = xorList.size() - 1; + size_t xcount = 0; + for ( ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); it++, xcount++ ) + { + printLongArg((*it)); + if ( xcount < xlen ) + std::cout << "OR" << std::endl; + } + + std::cout << "" << std::endl; + } + + // rest of args + for (ArgListIterator it = argList.begin(); it != argList.end(); it++) + if ( !xorHandler.contains( (*it) ) ) + printLongArg((*it)); + + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << "Version" << std::endl; + std::cout << "" << std::endl; + std::cout << version << std::endl; + std::cout << "" << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; std::cout << "" << std::endl; } @@ -152,5 +206,69 @@ inline void DocBookOutput::substituteSpecialChars( std::string& s, } } +inline void DocBookOutput::removeChar( std::string& s, char r) +{ + size_t p; + while ( (p = s.find_first_of(r)) != std::string::npos ) + { + s.erase(p,1); + } +} + +inline void DocBookOutput::printShortArg(Arg* a) +{ + std::string lt = "<"; + std::string gt = ">"; + + std::string id = a->shortID(); + substituteSpecialChars(id,'<',lt); + substituteSpecialChars(id,'>',gt); + removeChar(id,'['); + removeChar(id,']'); + + std::string choice = "opt"; + if ( a->isRequired() ) + choice = "req"; + + std::string repeat = "norepeat"; + if ( a->acceptsMultipleValues() ) + repeat = "repeat"; + + + + std::cout << "" + << id << "" << std::endl; + +} + +inline void DocBookOutput::printLongArg(Arg* a) +{ + std::string lt = "<"; + std::string gt = ">"; + + std::string id = a->longID(); + substituteSpecialChars(id,'<',lt); + substituteSpecialChars(id,'>',gt); + removeChar(id,'['); + removeChar(id,']'); + + std::string desc = a->getDescription(); + substituteSpecialChars(desc,'<',lt); + substituteSpecialChars(desc,'>',gt); + + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << id << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; + std::cout << desc << std::endl; + std::cout << "" << std::endl; + + std::cout << "" << std::endl; +} + } //namespace TCLAP #endif diff --git a/include/tclap/MultiArg.h b/include/tclap/MultiArg.h index cc0e5b3..0431fa7 100644 --- a/include/tclap/MultiArg.h +++ b/include/tclap/MultiArg.h @@ -340,7 +340,9 @@ MultiArg::MultiArg(const std::string& flag, _typeDesc( typeDesc ), _constraint( NULL ), _allowMore(false) -{ } +{ + _acceptsMultipleValues = true; +} template MultiArg::MultiArg(const std::string& flag, @@ -356,6 +358,7 @@ MultiArg::MultiArg(const std::string& flag, _allowMore(false) { parser.add( this ); + _acceptsMultipleValues = true; } /** @@ -372,7 +375,9 @@ MultiArg::MultiArg(const std::string& flag, _typeDesc( constraint->shortID() ), _constraint( constraint ), _allowMore(false) -{ } +{ + _acceptsMultipleValues = true; +} template MultiArg::MultiArg(const std::string& flag, @@ -388,6 +393,7 @@ MultiArg::MultiArg(const std::string& flag, _allowMore(false) { parser.add( this ); + _acceptsMultipleValues = true; } template