mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-08-04 10:16:41 -04:00
updated docbook output
This commit is contained in:
parent
ff6ad98c1e
commit
d46a014716
@ -125,6 +125,8 @@ class Arg
|
|||||||
*/
|
*/
|
||||||
bool _xorSet;
|
bool _xorSet;
|
||||||
|
|
||||||
|
bool _acceptsMultipleValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the special handling described by the Vistitor.
|
* Performs the special handling described by the Vistitor.
|
||||||
*/
|
*/
|
||||||
@ -330,6 +332,7 @@ class Arg
|
|||||||
void setRequireLabel( const std::string& s );
|
void setRequireLabel( const std::string& s );
|
||||||
|
|
||||||
virtual bool allowMore();
|
virtual bool allowMore();
|
||||||
|
virtual bool acceptsMultipleValues();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -368,7 +371,8 @@ inline Arg::Arg(const std::string& flag,
|
|||||||
_alreadySet(false),
|
_alreadySet(false),
|
||||||
_visitor( v ),
|
_visitor( v ),
|
||||||
_ignoreable(true),
|
_ignoreable(true),
|
||||||
_xorSet(false)
|
_xorSet(false),
|
||||||
|
_acceptsMultipleValues(false)
|
||||||
{
|
{
|
||||||
if ( _flag.length() > 1 )
|
if ( _flag.length() > 1 )
|
||||||
throw(SpecificationException(
|
throw(SpecificationException(
|
||||||
@ -567,6 +571,11 @@ inline bool Arg::allowMore()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool Arg::acceptsMultipleValues()
|
||||||
|
{
|
||||||
|
return _acceptsMultipleValues;
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
//END Arg.cpp
|
//END Arg.cpp
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
@ -76,6 +76,10 @@ class DocBookOutput : public CmdLineOutput
|
|||||||
* \param x - What to replace r with.
|
* \param x - What to replace r with.
|
||||||
*/
|
*/
|
||||||
void substituteSpecialChars( std::string& s, char r, std::string& x );
|
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<Arg*> argList = _cmd.getArgList();
|
std::list<Arg*> argList = _cmd.getArgList();
|
||||||
std::string progName = _cmd.getProgramName();
|
std::string progName = _cmd.getProgramName();
|
||||||
|
std::string version = _cmd.getVersion();
|
||||||
XorHandler xorHandler = _cmd.getXorHandler();
|
XorHandler xorHandler = _cmd.getXorHandler();
|
||||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
std::vector< std::vector<Arg*> > 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 << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
|
||||||
|
|
||||||
std::cout << "<book>" << std::endl;
|
std::cout << "<book>" << std::endl;
|
||||||
|
std::cout << "<refentry>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "<refmeta>" << std::endl;
|
||||||
|
std::cout << "<refentrytitle>" << std::endl;
|
||||||
|
std::cout << progName << std::endl;
|
||||||
|
std::cout << "</refentrytitle>" << std::endl;
|
||||||
|
std::cout << "<manvolnum>1</manvolnum>" << std::endl;
|
||||||
|
std::cout << "</refmeta>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "<refnamediv>" << std::endl;
|
||||||
|
std::cout << "<refname>" << std::endl;
|
||||||
|
std::cout << progName << std::endl;
|
||||||
|
std::cout << "</refname>" << std::endl;
|
||||||
|
std::cout << "</refnamediv>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<cmdsynopsis>" << std::endl;
|
std::cout << "<cmdsynopsis>" << std::endl;
|
||||||
|
|
||||||
std::cout << "<command>" << progName << "</command>" << std::endl;
|
std::cout << "<command>" << progName << "</command>" << std::endl;
|
||||||
|
|
||||||
std::string lt = "<";
|
|
||||||
std::string gt = ">";
|
|
||||||
|
|
||||||
// xor
|
// xor
|
||||||
for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
|
for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
|
||||||
{
|
{
|
||||||
std::cout << "<group>" << std::endl;
|
std::cout << "<group choice='req'>" << std::endl;
|
||||||
for ( ArgVectorIterator it = xorList[i].begin();
|
for ( ArgVectorIterator it = xorList[i].begin();
|
||||||
it != xorList[i].end(); it++ )
|
it != xorList[i].end(); it++ )
|
||||||
{
|
printShortArg((*it));
|
||||||
std::string id = (*it)->shortID();
|
|
||||||
substituteSpecialChars(id,'<',lt);
|
|
||||||
substituteSpecialChars(id,'>',gt);
|
|
||||||
std::cout << "<arg>" << id << "</arg>" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "</group>" << std::endl;
|
std::cout << "</group>" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rest of args
|
||||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||||
if ( !xorHandler.contains( (*it) ) )
|
if ( !xorHandler.contains( (*it) ) )
|
||||||
{
|
printShortArg((*it));
|
||||||
std::string id = (*it)->shortID();
|
|
||||||
substituteSpecialChars(id,'<',lt);
|
|
||||||
substituteSpecialChars(id,'>',gt);
|
|
||||||
std::cout << "<arg>" << id << "</arg>" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "</cmdsynopsis>" << std::endl;
|
std::cout << "</cmdsynopsis>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "<refsect1>" << std::endl;
|
||||||
|
std::cout << "<title>Description</title>" << std::endl;
|
||||||
|
std::cout << "<para>" << std::endl;
|
||||||
|
std::cout << _cmd.getMessage() << std::endl;
|
||||||
|
std::cout << "</para>" << std::endl;
|
||||||
|
std::cout << "</refsect1>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "<refsect1>" << std::endl;
|
||||||
|
std::cout << "<title>Options</title>" << std::endl;
|
||||||
|
std::cout << "<para>" << std::endl;
|
||||||
|
std::cout << "<itemizedlist>" << std::endl;
|
||||||
|
// xor
|
||||||
|
for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
|
||||||
|
{
|
||||||
|
std::cout << "<itemizedlist>" << 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 << "<listitem>OR</listitem>" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "</itemizedlist>" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rest of args
|
||||||
|
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||||
|
if ( !xorHandler.contains( (*it) ) )
|
||||||
|
printLongArg((*it));
|
||||||
|
|
||||||
|
std::cout << "</itemizedlist>" << std::endl;
|
||||||
|
std::cout << "</para>" << std::endl;
|
||||||
|
std::cout << "</refsect1>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "<refsect1>" << std::endl;
|
||||||
|
std::cout << "<title>Version</title>" << std::endl;
|
||||||
|
std::cout << "<para>" << std::endl;
|
||||||
|
std::cout << version << std::endl;
|
||||||
|
std::cout << "</para>" << std::endl;
|
||||||
|
std::cout << "</refsect1>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "</refentry>" << std::endl;
|
||||||
std::cout << "</book>" << std::endl;
|
std::cout << "</book>" << 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 << "<arg choice='" << choice
|
||||||
|
<< "' repeat='" << repeat << "'>"
|
||||||
|
<< id << "</arg>" << 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 << "<simplelist>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "<member>" << std::endl;
|
||||||
|
std::cout << id << std::endl;
|
||||||
|
std::cout << "</member>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "<member>" << std::endl;
|
||||||
|
std::cout << desc << std::endl;
|
||||||
|
std::cout << "</member>" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "</simplelist>" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace TCLAP
|
} //namespace TCLAP
|
||||||
#endif
|
#endif
|
||||||
|
@ -340,7 +340,9 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
|||||||
_typeDesc( typeDesc ),
|
_typeDesc( typeDesc ),
|
||||||
_constraint( NULL ),
|
_constraint( NULL ),
|
||||||
_allowMore(false)
|
_allowMore(false)
|
||||||
{ }
|
{
|
||||||
|
_acceptsMultipleValues = true;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
MultiArg<T>::MultiArg(const std::string& flag,
|
MultiArg<T>::MultiArg(const std::string& flag,
|
||||||
@ -356,6 +358,7 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
|||||||
_allowMore(false)
|
_allowMore(false)
|
||||||
{
|
{
|
||||||
parser.add( this );
|
parser.add( this );
|
||||||
|
_acceptsMultipleValues = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -372,7 +375,9 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
|||||||
_typeDesc( constraint->shortID() ),
|
_typeDesc( constraint->shortID() ),
|
||||||
_constraint( constraint ),
|
_constraint( constraint ),
|
||||||
_allowMore(false)
|
_allowMore(false)
|
||||||
{ }
|
{
|
||||||
|
_acceptsMultipleValues = true;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
MultiArg<T>::MultiArg(const std::string& flag,
|
MultiArg<T>::MultiArg(const std::string& flag,
|
||||||
@ -388,6 +393,7 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
|||||||
_allowMore(false)
|
_allowMore(false)
|
||||||
{
|
{
|
||||||
parser.add( this );
|
parser.add( this );
|
||||||
|
_acceptsMultipleValues = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user