23 #ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H 24 #define TCLAP_ZSHCOMPLETIONOUTPUT_H 82 std::map<std::string, std::string>
common;
87 : common(std::map<std::string, std::string>()),
91 common[
"hostname"] =
"_hosts";
93 common[
"filename"] =
"_files";
95 common[
"username"] =
"_users";
96 common[
"directory"] =
"_directories";
97 common[
"path"] =
"_directories";
114 std::cout <<
"#compdef " << progName << std::endl << std::endl <<
115 "# " << progName <<
" version " << _cmd.
getVersion() << std::endl << std::endl <<
120 if ( (*it)->shortID().at(0) ==
'<' )
122 else if ( (*it)->getFlag() !=
"-" )
126 std::cout << std::endl;
132 static_cast<void>(_cmd);
133 std::cout << e.
what() << std::endl;
138 size_t idx = s.find_last_of(
':');
139 while ( idx != std::string::npos )
141 s.insert(idx, 1,
'\\');
142 idx = s.find_last_of(
':', idx);
144 idx = s.find_last_of(
'\'');
145 while ( idx != std::string::npos )
147 s.insert(idx,
"'\\'");
149 idx = std::string::npos;
151 idx = s.find_last_of(
'\'', --idx);
157 size_t p = s.find_last_of(
'/');
158 if ( p != std::string::npos )
166 static int count = 1;
168 std::cout <<
" \\" << std::endl <<
" '";
172 std::cout << count++;
177 std::cout << a->
getName() <<
':';
178 std::map<std::string, std::string>::iterator compArg =
common.find(a->
getName());
179 if ( compArg !=
common.end() )
181 std::cout << compArg->second;
185 std::cout <<
"_guard \"^-*\" " << a->
getName();
198 if (!desc.compare(0, 12,
"(required) "))
202 if (!desc.compare(0, 15,
"(OR required) "))
206 size_t len = desc.length();
207 if (len && desc.at(--len) ==
'.')
213 desc.replace(0, 1, 1, tolower(desc.at(0)));
216 std::cout <<
" \\" << std::endl <<
" '" << mutex;
224 std::cout <<
"'{" << flag <<
',' << name <<
"}'";
229 std::cout <<
'[' << desc <<
']';
233 std::string arg = a->
shortID();
235 if ( arg.at(arg.length()-1) ==
']' )
236 arg.erase(arg.length()-1);
237 if ( arg.at(arg.length()-1) ==
']' )
239 arg.erase(arg.length()-1);
241 if ( arg.at(0) ==
'<' )
243 arg.erase(arg.length()-1);
246 size_t p = arg.find(
'|');
247 if ( p != std::string::npos )
251 arg.replace(p, 1, 1,
' ');
253 while ( (p = arg.find_first_of(
'|', p)) != std::string::npos );
255 std::cout <<
": :(" << arg <<
')';
259 std::cout <<
':' << arg;
260 std::map<std::string, std::string>::iterator compArg =
common.find(arg);
261 if ( compArg !=
common.end() )
263 std::cout <<
':' << compArg->second;
274 std::vector< std::vector<Arg*> > xorList = xorHandler.
getXorList();
281 std::ostringstream list;
287 for (
int i = 0;
static_cast<unsigned int>(i) < xorList.size(); i++ )
290 it != xorList[i].end();
296 iu != xorList[i].end();
299 bool notCur = (*iu) != a;
300 bool hasFlag = !(*iu)->
getFlag().empty();
301 if ( iu != xorList[i].begin() && (notCur || hasFlag) )
304 list << (*iu)->flagStartChar() << (*iu)->getFlag() <<
' ';
305 if ( notCur || hasFlag )
306 list << (*iu)->nameStartString() << (*iu)->getName();
std::vector< std::vector< Arg * > > & getXorList()
A virtual base class that defines the essential data for all arguments.
A simple class that defines and argument exception.
virtual std::string & getProgramName()=0
Returns the program name string.
static char flagStartChar()
virtual std::list< Arg * > & getArgList()=0
Returns the argList.
virtual char getDelimiter()=0
Returns the delimiter string.
void quoteSpecialChars(std::string &s)
virtual bool isRequired() const
Indicates whether the argument is required.
virtual std::string & getVersion()=0
Returns the version string.
virtual void version(CmdLineInterface &c)
Prints the version to stdout.
void printOption(Arg *it, std::string mutex)
void basename(std::string &s)
virtual XorHandler & getXorHandler()=0
Returns the XorHandler.
static const std::string nameStartString()
virtual void usage(CmdLineInterface &c)
Prints the usage to stdout.
const std::string & getName() const
Returns the argument name.
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
The base class that manages the command line definition and passes along the parsing to the appropria...
bool isValueRequired() const
Indicates whether a value must be specified for argument.
virtual bool acceptsMultipleValues()
Use by output classes to determine whether an Arg accepts multiple values.
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
std::string getDescription() const
Returns the argument description.
const std::string & getFlag() const
Returns the argument flag.
std::map< std::string, std::string > common
std::string getMutexList(CmdLineInterface &_cmd, Arg *a)
This class handles lists of Arg's that are to be XOR'd on the command line.
virtual void failure(CmdLineInterface &c, ArgException &e)
Prints (to stderr) an error message, short usage Can be overridden to produce alternative behavior...
const char * what() const
Returns the arg id and error text.
The interface that any output object must implement.
A class that generates a Zsh completion function as output from the usage() method for the given CmdL...