QCommandLineParser: Ensure that an option text ends with a newline
Before this change we inserted newline only if an option has a description and ended up with an arbitrary long line with all options. [ChangeLog][QtCore][QCommandLineParser] Fixed a bug that caused the help output to show two options or more in the same line if the options didn't have a description. Task-number: QTBUG-70174 Change-Id: Id54b9ae13ee596869e4dc14e09301aea19eed2f8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ef4ba0285f
commit
94884246d4
@ -1049,7 +1049,11 @@ QString QCommandLineParser::helpText() const
|
|||||||
static QString wrapText(const QString &names, int longestOptionNameString, const QString &description)
|
static QString wrapText(const QString &names, int longestOptionNameString, const QString &description)
|
||||||
{
|
{
|
||||||
const QLatin1Char nl('\n');
|
const QLatin1Char nl('\n');
|
||||||
QString text = QLatin1String(" ") + names.leftJustified(longestOptionNameString) + QLatin1Char(' ');
|
const QLatin1String indentation(" ");
|
||||||
|
if (description.isEmpty())
|
||||||
|
return indentation + names + nl;
|
||||||
|
|
||||||
|
QString text = indentation + names.leftJustified(longestOptionNameString) + QLatin1Char(' ');
|
||||||
const int indent = text.length();
|
const int indent = text.length();
|
||||||
int lineStart = 0;
|
int lineStart = 0;
|
||||||
int lastBreakable = -1;
|
int lastBreakable = -1;
|
||||||
|
@ -53,6 +53,7 @@ int main(int argc, char *argv[])
|
|||||||
parser.addOption(QCommandLineOption("load", "Load file from URL.", "url"));
|
parser.addOption(QCommandLineOption("load", "Load file from URL.", "url"));
|
||||||
parser.addOption(QCommandLineOption(QStringList() << "o" << "output", "Set output file.", "file"));
|
parser.addOption(QCommandLineOption(QStringList() << "o" << "output", "Set output file.", "file"));
|
||||||
parser.addOption(QCommandLineOption("D", "Define macro.", "key=value"));
|
parser.addOption(QCommandLineOption("D", "Define macro.", "key=value"));
|
||||||
|
parser.addOption(QCommandLineOption("long-option"));
|
||||||
|
|
||||||
// An option with a longer description, to test wrapping
|
// An option with a longer description, to test wrapping
|
||||||
QCommandLineOption noImplicitIncludesOption(QStringList() << QStringLiteral("n") << QStringLiteral("no-implicit-includes"));
|
QCommandLineOption noImplicitIncludesOption(QStringList() << QStringLiteral("n") << QStringLiteral("no-implicit-includes"));
|
||||||
|
@ -536,6 +536,7 @@ static const char expectedOptionsHelp[] =
|
|||||||
" --load <url> Load file from URL.\n"
|
" --load <url> Load file from URL.\n"
|
||||||
" -o, --output <file> Set output file.\n"
|
" -o, --output <file> Set output file.\n"
|
||||||
" -D <key=value> Define macro.\n"
|
" -D <key=value> Define macro.\n"
|
||||||
|
" --long-option\n"
|
||||||
" -n, --no-implicit-includes Disable magic generation of implicit\n"
|
" -n, --no-implicit-includes Disable magic generation of implicit\n"
|
||||||
" #include-directives.\n"
|
" #include-directives.\n"
|
||||||
" --newline This is an option with a rather long\n"
|
" --newline This is an option with a rather long\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user