diff options
| author | Kaloyan Chehlarski <kaloyan.chehlarski@qt.io> | 2024-08-23 14:24:24 +0200 |
|---|---|---|
| committer | David Faure <david.faure@kdab.com> | 2024-08-27 00:41:54 +0000 |
| commit | 61e91cb2812a2ba63354dbfb7a1fb4debcfcbe9e (patch) | |
| tree | 1e02cbbe95906d22ff3fff63489e8003216f202c /src/corelib/tools/qcommandlineparser.cpp | |
| parent | 8a0c86651f1e5091c4fb5ef8cbbcef53a9e336eb (diff) | |
QCommandLineParser: Support ignoring input past a certain option
This change adds a new flag to QCommandLineOption to indicate
that any command line options that follow are to be ignored by
QCommandLineParser. When an option with that flag is parsed,
any subsequent options are immediately skipped, and the parser
will return true, indicating success.
This is motivated by Qt WebEngine's need for being able to pass
through command line options from the host application to
the underlying Chromium. This is done by
using the --webEngineArgs option, which separates the Qt application
options (on the left), and the Chromium ones (on the right).
With this change, this mechanism will no longer clash with
QCommandLineParser's behavior of shutting the app down when
encountering an unknown option.
Change-Id: I31aedb7a18e551def742891623604513a329d7ca
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/tools/qcommandlineparser.cpp')
| -rw-r--r-- | src/corelib/tools/qcommandlineparser.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index ffe1193fc34..5aa1cc9d697 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -653,7 +653,12 @@ bool QCommandLineParserPrivate::parseOptionValue(const QString &optionName, cons if (nameHashIt != nameHash.constEnd()) { const qsizetype assignPos = argument.indexOf(assignChar); const NameHash_t::mapped_type optionOffset = *nameHashIt; - const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty(); + const QCommandLineOption &option = commandLineOptionList.at(optionOffset); + if (option.flags() & QCommandLineOption::IgnoreOptionsAfter) { + *argumentIterator = argsEnd; + return true; + } + const bool withValue = !option.valueName().isEmpty(); if (withValue) { if (assignPos == -1) { ++(*argumentIterator); |
