aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2017-03-31 16:39:45 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2017-04-03 11:41:00 +0000
commit0f62e829be66816831e1f04247dfb850912c3d50 (patch)
tree85d3f508689767f7e2f98370c17709e2a8ab3b9d
parent967f2262591556bdc72bcbb3339754ca8dd96203 (diff)
Handle digits in merged short options as option parameter
The argument list ["-a123b987"] becomes ["-a", "123", "-b", "987"]. Merged short options cannot be digits, e.g. ["-7j1"] is an error. This way we can support the "-j8" option that everybody knows and loves from make and other make'ish tools. Task-number: QBS-196 Change-Id: I574d77e8f85a708708ebed43668bb3c6ca916233 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/app/qbs/parser/parsercommand.cpp17
-rw-r--r--tests/auto/cmdlineparser/tst_cmdlineparser.cpp7
2 files changed, 22 insertions, 2 deletions
diff --git a/src/app/qbs/parser/parsercommand.cpp b/src/app/qbs/parser/parsercommand.cpp
index 40c4fa112..e10672aa9 100644
--- a/src/app/qbs/parser/parsercommand.cpp
+++ b/src/app/qbs/parser/parsercommand.cpp
@@ -104,8 +104,21 @@ void Command::parseOptions(QStringList &input)
// Split up grouped short options.
if (optionString.at(1) != QLatin1Char('-') && optionString.count() > 2) {
- for (int i = optionString.count(); --i > 0;)
- input.prepend(QLatin1Char('-') + optionString.at(i));
+ QString parameter;
+ for (int i = optionString.count(); --i > 0;) {
+ const QChar c = optionString.at(i);
+ if (c.isDigit()) {
+ parameter.prepend(c);
+ } else {
+ if (!parameter.isEmpty()) {
+ input.prepend(parameter);
+ parameter.clear();
+ }
+ input.prepend(QLatin1Char('-') + c);
+ }
+ }
+ if (!parameter.isEmpty())
+ throwError(Tr::tr("Unknown numeric option '%1'.").arg(parameter));
continue;
}
diff --git a/tests/auto/cmdlineparser/tst_cmdlineparser.cpp b/tests/auto/cmdlineparser/tst_cmdlineparser.cpp
index fcbb1bf14..92a202a45 100644
--- a/tests/auto/cmdlineparser/tst_cmdlineparser.cpp
+++ b/tests/auto/cmdlineparser/tst_cmdlineparser.cpp
@@ -140,6 +140,12 @@ private slots:
QCOMPARE(parser.buildConfigurations().count(), 1);
QCOMPARE(parser.buildConfigurations().first().value("qbs.configurationName").toString(), QLatin1String("debug"));
QCOMPARE(parser.buildConfigurations().first().value("qbs.profile").toString(), QLatin1String("b"));
+
+ // Digits are always handled as option parameters.
+ QVERIFY(parser.parseCommandLine(QStringList(fileArgs) << "-j" << "123"));
+ QCOMPARE(parser.buildOptions(QString()).maxJobCount(), 123);
+ QVERIFY(parser.parseCommandLine(QStringList(fileArgs) << "-j123"));
+ QCOMPARE(parser.buildOptions(QString()).maxJobCount(), 123);
}
void testInvalidCommandLine()
@@ -156,6 +162,7 @@ private slots:
QVERIFY(!parser.parseCommandLine(QStringList() << fileArgs << "--products")); // Missing argument.
QVERIFY(!parser.parseCommandLine(QStringList() << "--changed-files" << "," << fileArgs)); // Wrong argument.
QVERIFY(!parser.parseCommandLine(QStringList() << "--log-level" << "blubb" << fileArgs)); // Wrong argument.
+ QVERIFY(!parser.parseCommandLine(QStringList() << fileArgs << "-123")); // Unknown numeric argument.
}
void testProjectFileLookup()