Fix parsing args if no abbr or name is specified
This commit is contained in:
parent
01dee5de09
commit
324dc90b49
|
@ -477,14 +477,14 @@ void ArgumentParser::parseArgs(int argc, char *argv[])
|
||||||
// -> the full argument name has been provided
|
// -> the full argument name has been provided
|
||||||
givenId = givenArg.substr(2, equationPos - 2);
|
givenId = givenArg.substr(2, equationPos - 2);
|
||||||
pred = [&givenId, equationPos] (Argument *arg) {
|
pred = [&givenId, equationPos] (Argument *arg) {
|
||||||
return arg->name() == givenId;
|
return arg->name() && arg->name() == givenId;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// the argument starts with a single '-'
|
// the argument starts with a single '-'
|
||||||
// -> the abbreviation has been provided
|
// -> the abbreviation has been provided
|
||||||
givenId = givenArg.substr(1, equationPos - 1);
|
givenId = givenArg.substr(1, equationPos - 1);
|
||||||
pred = [&givenId, equationPos] (Argument *arg) {
|
pred = [&givenId, equationPos] (Argument *arg) {
|
||||||
return arg->abbreviation() == givenId;
|
return arg->abbreviation() && arg->abbreviation() == givenId;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// find the corresponding instance of the Argument class
|
// find the corresponding instance of the Argument class
|
||||||
|
@ -531,7 +531,7 @@ void ArgumentParser::parseArgs(int argc, char *argv[])
|
||||||
if(i == argv + 1) {
|
if(i == argv + 1) {
|
||||||
for(Argument *arg : m_mainArgs) {
|
for(Argument *arg : m_mainArgs) {
|
||||||
if(!arg->isPresent() && arg->denotesOperation()
|
if(!arg->isPresent() && arg->denotesOperation()
|
||||||
&& (arg->name() == givenArg || arg->abbreviation() == givenArg)) {
|
&& ((arg->name() && arg->name() == givenArg) || (arg->abbreviation() && arg->abbreviation() == givenArg))) {
|
||||||
currentArg = arg;
|
currentArg = arg;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue