Skip to content

Commit dc801f9

Browse files
lassoanjcfr
authored andcommitted
BUG: Fixed multi-value argument parsing
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.
1 parent 468e813 commit dc801f9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: Base/ctkCommandLineParser.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ QHash<QString, QVariant> ctkCommandLineParser::parseArguments(const QStringList&
412412
{
413413
qDebug() << " Processing parameter" << j << ", value:" << parameter;
414414
}
415-
if (this->argumentAdded(parameter))
415+
if (this->Internal->argumentDescription(parameter) != 0)
416416
{
417+
// we've found a known argument, it means there are no more
418+
// parameter for the current argument
417419
this->Internal->ErrorString =
418420
missingParameterError.arg(argument).arg(j-1).arg(numberOfParametersToProcess);
419421
if (this->Internal->Debug) { qDebug() << this->Internal->ErrorString; }
@@ -443,12 +445,15 @@ QHash<QString, QVariant> ctkCommandLineParser::parseArguments(const QStringList&
443445
int j = 1;
444446
while(j + i < arguments.size())
445447
{
446-
if (this->argumentAdded(arguments.at(j + i)))
448+
if (this->Internal->argumentDescription(arguments.at(j + i)) != 0)
447449
{
450+
// we've found a known argument, it means there are no more
451+
// parameter for the current argument
448452
if (this->Internal->Debug)
449453
{
450454
qDebug() << " No more parameter for" << argument;
451455
}
456+
j--; // this parameter does not belong to current argument
452457
break;
453458
}
454459
QString parameter = arguments.at(j + i);

0 commit comments

Comments
 (0)