From a5eb729c9d187a90f7be97f29f5bc5f9bcac39c7 Mon Sep 17 00:00:00 2001 From: Ariya Hidayat Date: Sun, 2 Sep 2012 00:22:34 -0700 Subject: [PATCH] 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 --- src/qcommandline/qcommandline.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/qcommandline/qcommandline.cpp b/src/qcommandline/qcommandline.cpp index 59401d19..8317cf75 100644 --- a/src/qcommandline/qcommandline.cpp +++ b/src/qcommandline/qcommandline.cpp @@ -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("="); + if (entry.type == QCommandLine::Option) { + if (entry.shortName != QLatin1Char('\0')) + val = QLatin1String("-") + QString(entry.shortName) + QLatin1Char(','); + val += QLatin1String("--") + entry.longName + QLatin1String("="); + } 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; }