17 :p_enableHelpOption(enableHelpOption), p_programVersion(programVersion)
77 bool isRequired,
const std::string & docString)
81 Option option(longOption, shortOption, value, isRequired, docString);
95 bool isRequired,
bool isAllowEmpty,
const std::string & docString)
99 Option option(longOption, shortOption, value, isRequired, docString);
107 cout <<
"Usage :" << endl;
111 cout <<
"Parameters :" << endl;
112 VecMode::const_iterator it(
p_vecMode.begin());
127 if(
parser.isBashCompletionMode()){
154 if(it->getName() == name){
167 if(it->getName() == name){
180 VecMode::const_iterator it(
p_vecMode.begin());
181 while(isSearch && it !=
p_vecMode.end()){
182 isSearch &= it->getName() != name;
213 while(!
parser.isEndOfOption()){
215 if(
parser.getCurrentOption() ==
"--help" ||
parser.getCurrentOption() ==
"-h"){
221 if(
parser.getCurrentOption() ==
"--version" ||
parser.getCurrentOption() ==
"-v"){
228 std::string modeName(currentMode.
getName());
229 std::string modeError(
"");
231 modeError =
" in mode '"+modeName+
"' ";
233 throw std::runtime_error(
"OptionParser::parseArgument : unknown option '"+
parser.getCurrentOption()+
"'" + modeError);
237 throw std::runtime_error(
"OptionParser::parseArgument : missing argument");
246 std::string cursorOption(
parser.getCursorOption());
247 std::string prevCursorOption(
parser.getPrevCursorOption());
248 Option * partialOption = NULL;
249 while(!
parser.isEndOfOption()){
251 VecMode::iterator itMode =
p_vecMode.begin();
252 while(!
parser.isEndOfOption() && itMode !=
p_vecMode.end() && isSearch){
253 isSearch = !itMode->parseOption(
parser, partialOption);
268 std::string possibleValue(
"");
271 std::cout << possibleValue << std::endl;
274 std::string possibleOption(
"");
279 std::cout << possibleOption << std::endl;
294 VecMode::const_iterator it(
p_vecMode.begin());
296 isArgOk = it->checkArgument();
307 std::string currentOption(
parser.getCurrentOption());
323 VecMode::const_iterator it(
p_vecMode.begin());
324 while(it !=
p_vecMode.end() && mode == NULL){
325 if(it->isCurrentlyParsed() && it->getName() !=
""){
340 std::string valueToBeCompleted(
"");
360 if(cursorOption ==
""){
return NULL;}
362 VecMode::const_iterator itMode(
p_vecMode.begin());
363 while(itMode !=
p_vecMode.end() && op == NULL){
364 if(itMode->isCurrentlyParsed()){
365 const VecOption & vecOp = itMode->getVecOption();
366 VecOption::const_iterator itOp(vecOp.begin());
367 while(itOp != vecOp.end() && op == NULL){
368 std::string fullOp(
"--" + itOp->getLongName() +
"=");
371 valueToBeCompleted = cursorOption.substr(fullOp.size());
388 if(prevCursorOption ==
""){
return NULL;}
390 VecMode::const_iterator itMode(
p_vecMode.begin());
391 while(itMode !=
p_vecMode.end() && op == NULL){
392 if(itMode->isCurrentlyParsed()){
393 const VecOption & vecOp = itMode->getVecOption();
394 VecOption::const_iterator itOp(vecOp.begin());
395 while(itOp != vecOp.end() && op == NULL){
396 std::string fullLongOp(
"--" + itOp->getLongName()), fullShortOption(
"-" + itOp->getShortName());
397 if(fullLongOp == prevCursorOption){
399 valueToBeCompleted = cursorOption;
400 }
else if(fullShortOption == prevCursorOption){
402 valueToBeCompleted = cursorOption;
418 p_vecMode.front().getPossibleOption(possibleOption, cursorOption);
421 if(currentlyParsedMode != NULL){
424 for(VecMode::const_iterator itMode =
p_vecMode.begin(); itMode !=
p_vecMode.end(); ++itMode){
425 itMode->getPossibleMode(possibleOption, cursorOption);
436 std::vector<std::string> vecOtherOption;
437 vecOtherOption.push_back(
"--help");
438 vecOtherOption.push_back(
"-h");
439 vecOtherOption.push_back(
"--version");
440 vecOtherOption.push_back(
"-v");
442 for(std::vector<std::string>::iterator it(vecOtherOption.begin()); it != vecOtherOption.end(); ++it){
443 std::string optionStr(*it);
444 if(cursorOption ==
""){
445 possibleOption += optionStr +
" ";
448 possibleOption += optionStr +
" ";