23 #ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H
24 #define TCLAP_ZSHCOMPLETIONOUTPUT_H
43 class ZshCompletionOutput :
public CmdLineOutput
55 virtual void usage(CmdLineInterface& c);
62 virtual void version(CmdLineInterface& c);
70 virtual void failure(CmdLineInterface& c,
78 std::string
getMutexList( CmdLineInterface& _cmd, Arg* a );
82 std::map<std::string, std::string>
common;
87 : common(std::map<std::string, std::string>()),
90 common[
"host"] =
"_hosts";
91 common[
"hostname"] =
"_hosts";
92 common[
"file"] =
"_files";
93 common[
"filename"] =
"_files";
94 common[
"user"] =
"_users";
95 common[
"username"] =
"_users";
96 common[
"directory"] =
"_directories";
97 common[
"path"] =
"_directories";
98 common[
"url"] =
"_urls";
103 std::cout << _cmd.getVersion() << std::endl;
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();
192 std::string flag = a->flagStartChar() + a->getFlag();
193 std::string name = a->nameStartString() + a->getName();
194 std::string desc = a->getDescription();
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;
218 if ( a->getFlag().empty() )
224 std::cout <<
"'{" << flag <<
',' << name <<
"}'";
229 std::cout <<
'[' << desc <<
']';
231 if ( a->isValueRequired() )
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;
273 XorHandler xorHandler = _cmd.getXorHandler();
274 std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
276 if (a->getName() ==
"help" || a->getName() ==
"version")
281 std::ostringstream list;
282 if ( a->acceptsMultipleValues() )
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();
314 if (!a->getFlag().empty()) {
315 list <<
"(" << a->flagStartChar() << a->getFlag() <<
' ' <<
316 a->nameStartString() << a->getName() <<
')';