diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2016-03-17 12:48:38 +0100 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2016-03-23 01:08:28 +0000 |
commit | 63274c95a3d78fbed8f511690cf7b248a6231273 (patch) | |
tree | 1e3beac941dad6057e5d8c1e3b3b3051e97b77e8 /src/corelib/tools/qcommandlineparser.cpp | |
parent | 17d3825874b1333a0aa50ba1b8fe1c51d9c9a8db (diff) |
Add QCommandLineOption::Flags containing HiddenFromHelp and ShortOptionStyle
This patch adds a new option, QCommandLineOption::ShortOptionStyle, which helps
applications (such as compilers, so moc and now qdoc) which need to mix long-style
and short flags.
[ChangeLog][QtCore][QCommandLineOption] Added flags() and setFlags() methods.
Added ShortOptionStyle and HiddenFromHelp flags.
Change-Id: I944ce56aff2b28ecd6bb9d2d23c4e726e9d06647
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/tools/qcommandlineparser.cpp')
-rw-r--r-- | src/corelib/tools/qcommandlineparser.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index 6587d900d2..81568681d8 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -295,7 +295,9 @@ QCommandLineParser::~QCommandLineParser() i.e. as the long option named \c{abc}. This is how Qt's own tools (uic, rcc...) have always been parsing arguments. This mode should be used for preserving compatibility in applications that were parsing - arguments in such a way. + arguments in such a way. There is an exception if the \c{a} option has the + QCommandLineOption::ShortOptionStyle flag set, in which case it is still + interpreted as \c{-a bc}. \sa setSingleDashWordOptionMode() */ @@ -762,6 +764,18 @@ bool QCommandLineParserPrivate::parse(const QStringList &args) } case QCommandLineParser::ParseAsLongOptions: { + if (argument.size() > 2) { + const QString possibleShortOptionStyleName = argument.mid(1, 1); + const auto shortOptionIt = nameHash.constFind(possibleShortOptionStyleName); + if (shortOptionIt != nameHash.constEnd()) { + const auto &arg = commandLineOptionList.at(*shortOptionIt); + if (arg.flags() & QCommandLineOption::ShortOptionStyle) { + registerFoundOption(possibleShortOptionStyleName); + optionValuesHash[*shortOptionIt].append(argument.mid(2)); + break; + } + } + } const QString optionName = argument.mid(1).section(assignChar, 0, 0); if (registerFoundOption(optionName)) { if (!parseOptionValue(optionName, argument, &argumentIterator, args.end())) @@ -1097,7 +1111,7 @@ QString QCommandLineParserPrivate::helpText() const optionNameList.reserve(commandLineOptionList.size()); int longestOptionNameString = 0; for (const QCommandLineOption &option : commandLineOptionList) { - if (option.isHidden()) + if (option.flags() & QCommandLineOption::HiddenFromHelp) continue; const QStringList optionNames = option.names(); QString optionNamesString; @@ -1116,7 +1130,7 @@ QString QCommandLineParserPrivate::helpText() const ++longestOptionNameString; auto optionNameIterator = optionNameList.cbegin(); for (const QCommandLineOption &option : commandLineOptionList) { - if (option.isHidden()) + if (option.flags() & QCommandLineOption::HiddenFromHelp) continue; text += wrapText(*optionNameIterator, longestOptionNameString, option.description()); ++optionNameIterator; |