From dc801f974219505e98edc442f022f60ec961589e Mon Sep 17 00:00:00 2001 From: Andras Lasso Date: Tue, 25 Apr 2017 08:35:07 -0400 Subject: [PATCH] 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. --- Base/ctkCommandLineParser.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Base/ctkCommandLineParser.cpp b/Base/ctkCommandLineParser.cpp index ada920f..56a56c2 100644 --- a/Base/ctkCommandLineParser.cpp +++ b/Base/ctkCommandLineParser.cpp @@ -412,8 +412,10 @@ QHash 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; } @@ -443,12 +445,15 @@ QHash 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);