Modify QCommandLine to suit our needs better.

Allow null shortname for options.
Do not include params in the help text.

http://code.google.com/p/phantomjs/issues/detail?id=55
1.7
Ariya Hidayat 2012-09-02 00:22:34 -07:00
parent 614259df0e
commit a5eb729c9d
1 changed files with 12 additions and 4 deletions

View File

@ -156,12 +156,14 @@ QCommandLine::parse()
bool allparam = false;
foreach (QCommandLineConfigEntry entry, d->config) {
#if 0
if (entry.type != QCommandLine::Param && entry.shortName == QLatin1Char('\0'))
qWarning() << QLatin1String("QCommandLine: Empty shortname detected");
if (entry.longName.isEmpty())
qWarning() << QLatin1String("QCommandLine: Empty shortname detected");
if (entry.type != QCommandLine::Param && conf.find(entry.shortName) != conf.end())
qWarning() << QLatin1String("QCommandLine: Duplicated shortname detected ") << entry.shortName;
#endif
if (conf.find(entry.longName) != conf.end())
qWarning() << QLatin1String("QCommandLine: Duplicated longname detected ") << entry.shortName;
@ -460,13 +462,17 @@ QCommandLine::help(bool logo)
foreach (QCommandLineConfigEntry entry, d->config) {
QString val;
if (entry.type == QCommandLine::Option)
val = QLatin1String("-") + QString(entry.shortName) +
QLatin1String(",--") + entry.longName + QLatin1String("=<val>");
if (entry.type == QCommandLine::Option) {
if (entry.shortName != QLatin1Char('\0'))
val = QLatin1String("-") + QString(entry.shortName) + QLatin1Char(',');
val += QLatin1String("--") + entry.longName + QLatin1String("=<val>");
}
if (entry.type == QCommandLine::Switch)
val = QLatin1String("-") + QString(entry.shortName) + QLatin1String(",--") + entry.longName;
#if 0
if (entry.type == QCommandLine::Param)
val = entry.longName;
#endif
if (val.size() > max)
max = val.size();
@ -476,14 +482,16 @@ QCommandLine::help(bool logo)
}
for (int i = 0; i < vals.size(); ++i) {
if (vals[i].isEmpty()) continue;
h.append(QLatin1String(" "));
h.append(vals[i]);
h.append(QString(QLatin1String(" ")).repeated(max - vals[i].size() + 2));
h.append(descrs[i]);
}
#if 0
h.append(tr("\nMandatory arguments to long options are mandatory for short options too.\n"));
#endif
return h;
}