diff options
| author | Christian Kandeler <christian.kandeler@digia.com> | 2013-04-05 15:38:44 +0200 |
|---|---|---|
| committer | Joerg Bornemann <joerg.bornemann@digia.com> | 2013-04-05 17:09:40 +0200 |
| commit | d14a9785cb9e781cd085518f2ac9e46dd451d707 (patch) | |
| tree | ac40ac5330ca4b34c792f17c1a27c11f3df067ea | |
| parent | a28ff4c7890a97098d50378eeddee41cd7bb83c2 (diff) | |
| download | qbs-d14a9785cb9e781cd085518f2ac9e46dd451d707.tar.gz | |
Sort commands and options by name in help output.
This makes it easier for users to find a specific command or option.
Change-Id: I8e08fc927ce5372e6eb3a64ecc7c98ae93617384
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
| -rw-r--r-- | src/app/qbs/parser/command.cpp | 10 | ||||
| -rw-r--r-- | src/app/qbs/parser/commandlineparser.cpp | 12 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/app/qbs/parser/command.cpp b/src/app/qbs/parser/command.cpp index 3b6f57e85..62fef3de6 100644 --- a/src/app/qbs/parser/command.cpp +++ b/src/app/qbs/parser/command.cpp @@ -35,6 +35,7 @@ #include <tools/error.h> #include <tools/hostosinfo.h> +#include <QMap> #include <QSet> namespace qbs { @@ -127,11 +128,16 @@ void Command::parseOptions(QStringList &input) QString Command::supportedOptionsDescription() const { - QString s = Tr::tr("The possible options are:\n"); + // Sorting the options by name is nicer for the user. + QMap<QString, const CommandLineOption *> optionMap; foreach (const CommandLineOption::Type opType, actualSupportedOptions()) { const CommandLineOption * const option = optionPool().getOption(opType); - s += option->description(type()); + optionMap.insert(option->longRepresentation(), option); } + + QString s = Tr::tr("The possible options are:\n"); + foreach (const CommandLineOption *option, optionMap) + s += option->description(type()); return s; } diff --git a/src/app/qbs/parser/commandlineparser.cpp b/src/app/qbs/parser/commandlineparser.cpp index 85027d113..18b45336c 100644 --- a/src/app/qbs/parser/commandlineparser.cpp +++ b/src/app/qbs/parser/commandlineparser.cpp @@ -46,6 +46,7 @@ #include <QCoreApplication> #include <QDir> +#include <QMap> #include <QTextStream> #ifdef Q_OS_UNIX @@ -328,14 +329,21 @@ QString CommandLineParser::CommandLineParserPrivate::generalHelp() const QString help = Tr::tr("Usage: qbs [command] [command parameters]\n"); help += Tr::tr("Internal commands:\n"); const int rhsIndentation = 30; - foreach (const Command * command, allCommands()) { + + // Sorting the commands by name is nicer for the user. + QMap<QString, const Command *> commandMap; + foreach (const Command * command, allCommands()) + commandMap.insert(command->representation(), command); + + foreach (const Command * command, commandMap) { help.append(QLatin1String(" ")).append(command->representation()); const QString whitespace = QString(rhsIndentation - 2 - command->representation().count(), QLatin1Char(' ')); help.append(whitespace).append(command->shortDescription()).append(QLatin1Char('\n')); } - const QStringList &toolNames = QbsTool::allToolNames(); + QStringList toolNames = QbsTool::allToolNames(); + toolNames.sort(); if (!toolNames.isEmpty()) { help.append('\n').append(Tr::tr("Auxiliary commands:\n")); foreach (const QString &toolName, toolNames) { |
