From 4bf453fb84c67283c85180dcf964526534f0ef72 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Tue, 22 Sep 2020 14:01:09 +0300 Subject: Expand the sanity check for mutually exclusive options Task-number: QTIFW-1744 Change-Id: I4a4fdcd2517028e05f9282c15a91a4fb83c24901 Reviewed-by: Iikka Eklund --- src/libs/installer/utils.cpp | 21 ++++++++++++++++++--- src/libs/installer/utils.h | 5 ++++- src/sdk/main.cpp | 34 +++++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/libs/installer/utils.cpp b/src/libs/installer/utils.cpp index d47caea89..e3a18100b 100644 --- a/src/libs/installer/utils.cpp +++ b/src/libs/installer/utils.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -182,6 +182,23 @@ uint QInstaller::verboseLevel() return verbLevel; } +/*! + Returns a list of mutually exclusive options passed to the \a parser, if there is + at least one mutually exclusive pair of options set. Otherwise returns an empty + \c QStringList. The options considered mutual are provided with \a options. +*/ +QStringList QInstaller::checkMutualOptions(CommandLineParser &parser, const QStringList &options) +{ + QStringList mutual; + foreach (const QString &option, options) { + if (parser.isSet(option)) + mutual << option; + } + return mutual.count() > 1 + ? mutual + : QStringList(); +} + /*! \internal */ @@ -512,5 +529,3 @@ QString QInstaller::windowsErrorString(int errorCode) } #endif - - diff --git a/src/libs/installer/utils.h b/src/libs/installer/utils.h index 74cc4917c..055f5cc0f 100644 --- a/src/libs/installer/utils.h +++ b/src/libs/installer/utils.h @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -30,6 +30,7 @@ #define QINSTALLER_UTILS_H #include "installer_global.h" +#include "commandlineparser.h" #include #include @@ -66,6 +67,8 @@ namespace QInstaller { bool INSTALLER_EXPORT isVerbose(); uint INSTALLER_EXPORT verboseLevel(); + QStringList INSTALLER_EXPORT checkMutualOptions(CommandLineParser &parser, const QStringList &options); + INSTALLER_EXPORT std::ostream& operator<<(std::ostream &os, const QString &string); class INSTALLER_EXPORT VerboseWriterOutput diff --git a/src/sdk/main.cpp b/src/sdk/main.cpp index ee4f9d74a..9b425bc98 100644 --- a/src/sdk/main.cpp +++ b/src/sdk/main.cpp @@ -85,17 +85,29 @@ int main(int argc, char *argv[]) QString sanityMessage; QStringList mutually; - if (parser.isSet(CommandLineOptions::scStartUpdaterLong)) - mutually << CommandLineOptions::scStartUpdaterLong; - if (parser.isSet(CommandLineOptions::scStartPackageManagerLong)) - mutually << CommandLineOptions::scStartPackageManagerLong; - if (parser.isSet(CommandLineOptions::scStartUninstallerLong)) - mutually << CommandLineOptions::scStartUninstallerLong; - // IFW 3.x.x style --updater option support provided for backward compatibility - if (parser.isSet(CommandLineOptions::scDeprecatedUpdater)) - mutually << CommandLineOptions::scDeprecatedUpdater; - - if (mutually.count() > 1) { + mutually = QInstaller::checkMutualOptions(parser, QStringList() + << CommandLineOptions::scStartUpdaterLong + << CommandLineOptions::scStartPackageManagerLong + << CommandLineOptions::scStartUninstallerLong + << CommandLineOptions::scDeprecatedUpdater); + + if (mutually.isEmpty()) { + mutually = QInstaller::checkMutualOptions(parser, QStringList() + << CommandLineOptions::scSystemProxyLong + << CommandLineOptions::scNoProxyLong); + } + if (mutually.isEmpty()) { + mutually = QInstaller::checkMutualOptions(parser, QStringList() + << CommandLineOptions::scAcceptMessageQuery + << CommandLineOptions::scRejectMessageQuery + << CommandLineOptions::scMessageDefaultAnswer); + } + if (mutually.isEmpty()) { + mutually = QInstaller::checkMutualOptions(parser, QStringList() + << CommandLineOptions::scStartServerLong + << CommandLineOptions::scStartClientLong); + } + if (!mutually.isEmpty()) { sanityMessage = QString::fromLatin1("The following options are mutually exclusive: %1.") .arg(mutually.join(QLatin1String(", "))); sanityCheck = false; -- cgit v1.2.3