diff options
Diffstat (limited to 'src/app/qbs/parser/commandlineparser.cpp')
-rw-r--r-- | src/app/qbs/parser/commandlineparser.cpp | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/src/app/qbs/parser/commandlineparser.cpp b/src/app/qbs/parser/commandlineparser.cpp index 0f70b3fe9..c548cf2b5 100644 --- a/src/app/qbs/parser/commandlineparser.cpp +++ b/src/app/qbs/parser/commandlineparser.cpp @@ -65,6 +65,7 @@ #include <QtCore/qmap.h> #include <QtCore/qtextstream.h> +#include <algorithm> #include <utility> #ifdef Q_OS_UNIX @@ -155,17 +156,11 @@ QString CommandLineParser::projectBuildDirectory() const BuildOptions CommandLineParser::buildOptions(const QString &profile) const { - Settings settings(settingsDir()); - Preferences preferences(&settings, profile); - - if (d->buildOptions.maxJobCount() <= 0) { - d->buildOptions.setMaxJobCount(preferences.jobs()); - } - + d->buildOptions.setMaxJobCount(jobCount(profile)); if (d->buildOptions.echoMode() < 0) { - d->buildOptions.setEchoMode(preferences.defaultEchoMode()); + Settings settings(settingsDir()); + d->buildOptions.setEchoMode(Preferences(&settings, profile).defaultEchoMode()); } - return d->buildOptions; } @@ -202,6 +197,15 @@ InstallOptions CommandLineParser::installOptions(const QString &profile) const return options; } +int CommandLineParser::jobCount(const QString &profile) const +{ + if (const int explicitJobCount = d->optionPool.jobsOption()->jobCount(); explicitJobCount > 0) + return explicitJobCount; + + Settings settings(settingsDir()); + return Preferences(&settings, profile).jobs(); +} + bool CommandLineParser::forceTimestampCheck() const { return d->optionPool.forceTimestampCheckOption()->enabled(); @@ -227,11 +231,6 @@ bool CommandLineParser::waitLockBuildGraph() const return d->optionPool.waitLockOption()->enabled(); } -bool CommandLineParser::disableFallbackProvider() const -{ - return d->optionPool.disableFallbackProviderOption()->enabled(); -} - bool CommandLineParser::logTime() const { return d->logTime; @@ -278,6 +277,11 @@ QString CommandLineParser::settingsDir() const return d->settingsDir(); } +DeprecationWarningMode CommandLineParser::deprecationWarningMode() const +{ + return d->optionPool.deprecationWarningsOption()->mode(); +} + QString CommandLineParser::commandName() const { return d->command->representation(); @@ -329,7 +333,19 @@ void CommandLineParser::CommandLineParserPrivate::doParse() } else { command = commandFromString(commandLine.front()); if (command) { - commandLine.removeFirst(); + const QString commandName = commandLine.takeFirst(); + + // if the command line contains a `<command>` with + // either `-h` or `--help` switch, we transform + // it to corresponding `help <command>` instead + const QStringList helpSwitches = {QStringLiteral("-h"), QStringLiteral("--help")}; + if (auto it = std::find_first_of( + commandLine.begin(), commandLine.end(), + helpSwitches.begin(), helpSwitches.end()); + it != commandLine.end()) { + command = commandPool.getCommand(HelpCommandType); + commandLine = QList{commandName}; // keep only command's name + } } else { // No command given. if (commandLine.front() == QLatin1String("-h") || commandLine.front() == QLatin1String("--help")) { @@ -408,7 +424,7 @@ QString CommandLineParser::CommandLineParserPrivate::generalHelp() const for (const Command * command : commands) commandMap.insert(command->representation(), command); - for (const Command * command : qAsConst(commandMap)) { + for (const Command * command : std::as_const(commandMap)) { help.append(QLatin1String(" ")).append(command->representation()); const QString whitespace = QString(rhsIndentation - 2 - command->representation().size(), QLatin1Char(' ')); @@ -419,7 +435,7 @@ QString CommandLineParser::CommandLineParserPrivate::generalHelp() const toolNames.sort(); if (!toolNames.empty()) { help.append(QLatin1Char('\n')).append(Tr::tr("Auxiliary commands:\n")); - for (const QString &toolName : qAsConst(toolNames)) { + for (const QString &toolName : std::as_const(toolNames)) { help.append(QLatin1String(" ")).append(toolName); const QString whitespace = QString(rhsIndentation - 2 - toolName.size(), QLatin1Char(' ')); @@ -502,7 +518,7 @@ void CommandLineParser::CommandLineParserPrivate::setupBuildConfigurations() const QVariantMap globalProperties = propertiesPerConfiguration.takeFirst().second; QList<QVariantMap> buildConfigs; - for (const PropertyListItem &item : qAsConst(propertiesPerConfiguration)) { + for (const PropertyListItem &item : std::as_const(propertiesPerConfiguration)) { QVariantMap properties = item.second; for (QVariantMap::ConstIterator globalPropIt = globalProperties.constBegin(); globalPropIt != globalProperties.constEnd(); ++globalPropIt) { |