Skip to content

Commit

Permalink
BUG: Fixed multi-value argument parsing
Browse files Browse the repository at this point in the history
When a multi-value argument was passed to the command-line parser, all subsequent parameters were considered part of the argument.

The root cause of the problem was that the check that compared a parameter to a known argument was incorrect: the parameter name
contained the prefix (--argname) and this string was searched among argument names (such as argname).

Fixed by parsing each parameter after a multi-value argument. If a known argument is found, it is not added to the multi-value argument.
  • Loading branch information
lassoan authored and jcfr committed Oct 10, 2017
1 parent 0e8c94e commit dad68fa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Base/ctkCommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,10 @@ QHash<QString, QVariant> ctkCommandLineParser::parseArguments(const QStringList&
{
qDebug() << " Processing parameter" << j << ", value:" << parameter;
}
if (this->argumentAdded(parameter))
if (this->Internal->argumentDescription(parameter) != 0)
{
// we've found a known argument, it means there are no more
// parameter for the current argument
this->Internal->ErrorString =
missingParameterError.arg(argument).arg(j-1).arg(numberOfParametersToProcess);
if (this->Internal->Debug) { qDebug() << this->Internal->ErrorString; }
Expand Down Expand Up @@ -443,12 +445,15 @@ QHash<QString, QVariant> ctkCommandLineParser::parseArguments(const QStringList&
int j = 1;
while(j + i < arguments.size())
{
if (this->argumentAdded(arguments.at(j + i)))
if (this->Internal->argumentDescription(arguments.at(j + i)) != 0)
{
// we've found a known argument, it means there are no more
// parameter for the current argument
if (this->Internal->Debug)
{
qDebug() << " No more parameter for" << argument;
}
j--; // this parameter does not belong to current argument
break;
}
QString parameter = arguments.at(j + i);
Expand Down

0 comments on commit dad68fa

Please sign in to comment.