24#ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H
25#define TCLAP_ZSHCOMPLETIONOUTPUT_H
88 std::map<std::string, std::string>
common;
93: common(std::map<std::string, std::string>()),
97 common[
"hostname"] =
"_hosts";
99 common[
"filename"] =
"_files";
100 common[
"user"] =
"_users";
101 common[
"username"] =
"_users";
102 common[
"directory"] =
"_directories";
103 common[
"path"] =
"_directories";
120 std::cout <<
"#compdef " << progName << std::endl << std::endl <<
121 "# " << progName <<
" version " << _cmd.
getVersion() << std::endl << std::endl <<
126 if ( (*it)->shortID().at(0) ==
'<' )
128 else if ( (*it)->getFlag() !=
"-" )
132 std::cout << std::endl;
138 static_cast<void>(_cmd);
139 std::cout << e.
what() << std::endl;
144 size_t idx = s.find_last_of(
':');
145 while ( idx != std::string::npos )
147 s.insert(idx, 1,
'\\');
148 idx = s.find_last_of(
':', idx);
150 idx = s.find_last_of(
'\'');
151 while ( idx != std::string::npos )
153 s.insert(idx,
"'\\'");
155 idx = std::string::npos;
157 idx = s.find_last_of(
'\'', --idx);
163 size_t p = s.find_last_of(
'/');
164 if ( p != std::string::npos )
172 static int count = 1;
174 std::cout <<
" \\" << std::endl <<
" '";
178 std::cout << count++;
183 std::cout << a->
getName() <<
':';
184 std::map<std::string, std::string>::iterator compArg =
common.find(a->
getName());
185 if ( compArg !=
common.end() )
187 std::cout << compArg->second;
191 std::cout <<
"_guard \"^-*\" " << a->
getName();
204 if (!desc.compare(0, 12,
"(required) "))
208 if (!desc.compare(0, 15,
"(OR required) "))
212 size_t len = desc.length();
213 if (len && desc.at(--len) ==
'.')
219 desc.replace(0, 1, 1, tolower(desc.at(0)));
222 std::cout <<
" \\" << std::endl <<
" '" << mutex;
230 std::cout <<
"'{" << flag <<
',' << name <<
"}'";
235 std::cout <<
'[' << desc <<
']';
239 std::string arg = a->
shortID();
241 size_t pos = arg.rfind(
" ... ");
242 if (pos != std::string::npos) {
247 if ( arg.at(arg.length()-1) ==
']' )
248 arg.erase(arg.length()-1);
249 if ( arg.at(arg.length()-1) ==
']' )
251 arg.erase(arg.length()-1);
253 if ( arg.at(0) ==
'<' )
255 arg.erase(arg.length()-1);
258 size_t p = arg.find(
'|');
259 if ( p != std::string::npos )
263 arg.replace(p, 1, 1,
' ');
265 while ( (p = arg.find_first_of(
'|', p)) != std::string::npos );
267 std::cout <<
": :(" << arg <<
')';
271 std::cout <<
':' << arg;
272 std::map<std::string, std::string>::iterator compArg =
common.find(arg);
273 if ( compArg !=
common.end() )
275 std::cout <<
':' << compArg->second;
286 std::vector< std::vector<Arg*> > xorList = xorHandler.
getXorList();
299 for (
int i = 0;
static_cast<unsigned int>(i) < xorList.size(); i++ )
302 it != xorList[i].end();
308 iu != xorList[i].end();
311 bool notCur = (*iu) != a;
312 bool hasFlag = !(*iu)->
getFlag().empty();
313 if ( iu != xorList[i].begin() && (notCur || hasFlag) )
316 list << (*iu)->flagStartChar() << (*iu)->getFlag() <<
' ';
317 if ( notCur || hasFlag )
318 list << (*iu)->nameStartString() << (*iu)->getName();
A simple class that defines and argument exception.
const char * what() const
Returns the arg id and error text.
A virtual base class that defines the essential data for all arguments.
static const std::string nameStartString()
const std::string & getFlag() const
Returns the argument flag.
bool isValueRequired() const
Indicates whether a value must be specified for argument.
static char flagStartChar()
const std::string & getName() const
Returns the argument name.
std::string getDescription() const
Returns the argument description.
virtual bool acceptsMultipleValues()
Use by output classes to determine whether an Arg accepts multiple values.
virtual bool isRequired() const
Indicates whether the argument is required.
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...
virtual XorHandler & getXorHandler()=0
Returns the XorHandler.
virtual std::list< Arg * > & getArgList()=0
Returns the argList.
virtual std::string & getProgramName()=0
Returns the program name string.
virtual char getDelimiter()=0
Returns the delimiter string.
virtual std::string & getVersion()=0
Returns the version string.
The interface that any output object must implement.
This class handles lists of Arg's that are to be XOR'd on the command line.
std::vector< std::vector< Arg * > > & getXorList()
A class that generates a Zsh completion function as output from the usage() method for the given CmdL...
void printOption(Arg *it, std::string mutex)
virtual void usage(CmdLineInterface &c)
Prints the usage to stdout.
void basename(std::string &s)
virtual void version(CmdLineInterface &c)
Prints the version to stdout.
std::map< std::string, std::string > common
void quoteSpecialChars(std::string &s)
virtual void failure(CmdLineInterface &c, ArgException &e)
Prints (to stderr) an error message, short usage Can be overridden to produce alternative behavior.
std::string getMutexList(CmdLineInterface &_cmd, Arg *a)
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
std::ostringstream ostringstream