hbristow / argparse

A slimline C++ class for parsing command-line arguments, with an interface similar to python's class of the same name
BSD 3-Clause "New" or "Revised" License
267 stars 68 forks source link

A problem with `exists` function #6

Open ahmad-siavashi opened 7 years ago

ahmad-siavashi commented 7 years ago

index_ variable is a map that holds the arguments that are added using addArgument.
The exists function is currently written as follows
bool exists(const String& name) const { return index_.count(delimit(name)) > 0; }

so a code like the one below will always enter the if's body, even if the clean argument has not been sent to the program,

parser.addArgument("-c", "--clean");
// parsing passed arguments
parser.parse(size_t(__argc), const_cast<const char **>(__argv));
if (parser.exists("clean")) { 
   // ...
}

This is inconsistent with the definition given for the exists function

exists() check if an argument has been found

Thank you for your efforts,
Sincerely,
Ahmad