1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-09-19 21:25:36 +01:00

option parser checks for duplicated options

This commit is contained in:
Antonin Portelli 2019-12-12 18:05:13 +00:00
parent 21812e1fd7
commit 1c55c93669

View File

@ -46,6 +46,33 @@ void OptParser::addOption(const std::string shortName,
par.helpMessage = helpMessage;
par.type = type;
par.optional = optional;
auto it = std::find_if(opt_.begin(), opt_.end(), [&par](const OptPar & p)
{
bool match = false;
match |= (par.shortName == p.shortName) and !par.shortName.empty();
match |= (par.longName == p.longName) and !par.longName.empty();
return match;
});
if (it != opt_.end())
{
string opt;
if (!it->shortName.empty())
{
opt += "-" + it->shortName;
}
if (!opt.empty())
{
opt += "/";
}
if (!it->longName.empty())
{
opt += "--" + it->longName;
}
throw(logic_error("duplicate option " + opt + " (in the code, not in the command line)"));
}
opt_.push_back(par);
}