1 From 8b825f662058c0e32d08f37f7bbb2243dcded8b0 Mon Sep 17 00:00:00 2001
2 From: Dan Callaghan <dcallagh@redhat.com>
3 Date: Thu, 10 Jan 2013 10:17:19 +1000
4 Subject: [PATCH 2/4] new NoShortName flag, to allow options with no short
7 This patch is based on the following phantomjs commit:
9 commit a5eb729c9d187a90f7be97f29f5bc5f9bcac39c7
10 Author: Ariya Hidayat <ariya.hidayat@gmail.com>
11 Date: Sun Sep 2 00:22:34 2012 -0700
13 Modify QCommandLine to suit our needs better.
15 Allow null shortname for options.
16 Do not include params in the help text.
18 http://code.google.com/p/phantomjs/issues/detail?id=55
20 src/qcommandline.cpp | 23 +++++++++++++++--------
21 src/qcommandline.h | 1 +
22 2 files changed, 16 insertions(+), 8 deletions(-)
24 diff --git a/src/qcommandline.cpp b/src/qcommandline.cpp
25 index c92a807..cb6e2ff 100644
26 --- a/src/qcommandline.cpp
27 +++ b/src/qcommandline.cpp
28 @@ -156,11 +156,13 @@ QCommandLine::parse()
29 bool allparam = false;
31 foreach (QCommandLineConfigEntry entry, d->config) {
32 - if (entry.type != QCommandLine::Param && entry.shortName == QLatin1Char('\0'))
33 + if (entry.type != QCommandLine::Param && !(entry.flags & QCommandLine::NoShortName)
34 + && entry.shortName == QLatin1Char('\0'))
35 qWarning() << QLatin1String("QCommandLine: Empty shortname detected");
36 if (entry.longName.isEmpty())
37 - qWarning() << QLatin1String("QCommandLine: Empty shortname detected");
38 - if (entry.type != QCommandLine::Param && conf.find(entry.shortName) != conf.end())
39 + qWarning() << QLatin1String("QCommandLine: Empty longname detected");
40 + if (entry.type != QCommandLine::Param && !(entry.flags & QCommandLine::NoShortName)
41 + && conf.find(entry.shortName) != conf.end())
42 qWarning() << QLatin1String("QCommandLine: Duplicated shortname detected ") << entry.shortName;
43 if (conf.find(entry.longName) != conf.end())
44 qWarning() << QLatin1String("QCommandLine: Duplicated longname detected ") << entry.shortName;
45 @@ -463,11 +465,16 @@ QCommandLine::help(bool logo)
46 foreach (QCommandLineConfigEntry entry, d->config) {
49 - if (entry.type == QCommandLine::Option)
50 - val = QLatin1String("-") + QString(entry.shortName) +
51 - QLatin1String(",--") + entry.longName + QLatin1String("=<val>");
52 - if (entry.type == QCommandLine::Switch)
53 - val = QLatin1String("-") + QString(entry.shortName) + QLatin1String(",--") + entry.longName;
54 + if (entry.type == QCommandLine::Option) {
55 + if (entry.shortName != QLatin1Char('\0'))
56 + val = QLatin1String("-") + QString(entry.shortName) + QLatin1Char(',');
57 + val += QLatin1String("--") + entry.longName + QLatin1String("=<val>");
59 + if (entry.type == QCommandLine::Switch) {
60 + if (entry.shortName != QLatin1Char('\0'))
61 + val = QLatin1String("-") + QString(entry.shortName) + QLatin1Char(',');
62 + val += QLatin1String("--") + entry.longName;
64 if (entry.type == QCommandLine::Param)
67 diff --git a/src/qcommandline.h b/src/qcommandline.h
68 index 2511127..4263f43 100644
69 --- a/src/qcommandline.h
70 +++ b/src/qcommandline.h
71 @@ -86,6 +86,7 @@ public:
72 MandatoryMultiple = Mandatory|Multiple,
73 OptionalMultiple = Optional|Multiple,
74 ParameterFence = 0x08, /**< all arguments after this point are considered parameters, not options. */
75 + NoShortName = 0x10, /**< switch or option having only a long name, no short name */