24 #ifndef TCLAP_ZSHCOMPLETIONOUTPUT_H
25 #define TCLAP_ZSHCOMPLETIONOUTPUT_H
49 class ZshCompletionOutput :
public CmdLineOutput
61 virtual void usage(CmdLineInterface& c);
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";
109 std::cout << _cmd.getVersion() << std::endl;
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();
198 std::string flag = a->flagStartChar() + a->getFlag();
199 std::string name = a->nameStartString() + a->getName();
200 std::string desc = a->getDescription();
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;
224 if ( a->getFlag().empty() )
230 std::cout <<
"'{" << flag <<
',' << name <<
"}'";
235 std::cout <<
'[' << desc <<
']';
237 if ( a->isValueRequired() )
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;
285 XorHandler xorHandler = _cmd.getXorHandler();
286 std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
288 if (a->getName() ==
"help" || a->getName() ==
"version")
294 if ( a->acceptsMultipleValues() )
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();
326 if (!a->getFlag().empty()) {
327 list <<
"(" << a->flagStartChar() << a->getFlag() <<
' ' <<
328 a->nameStartString() << a->getName() <<
')';