diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2020-03-11 18:35:05 +0200 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2020-03-19 06:56:52 +0200 |
commit | 8878f49cc00a5dcd0a8acd89cd5c9d8b89505941 (patch) | |
tree | 3db628af65c8f88067f8f49dcdedac1375fc1d38 | |
parent | ea8f8f2d8c9170dcf8c087786125db09c8d18dec (diff) |
Refactor naming and usage of CLI commands
- Rename and alter the description of some command line options
according to validation results from task QTIFW-1635. The
suggested additions are not added in this change.
- Remove options "framework-version" and "silentUpdate", these
should not be needed anymore.
- Combine options "installPackages" and "installDefault" into
single "install" command.
- Change command line syntax from "binary [options]" to
"binary [options] command <arguments>".
- Re-order & group known option variables and "--help" printing
order based on their topic.
- Move CommandLineParser class files under src/libs/installer
and add private class for future options extension.
Short versions of command line options should be added in a
follow-up commit.
Task-number: QTIFW-1671
Change-Id: Ie0d393368b5275c8ffa1ab8833885b149af3178e
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r-- | src/libs/installer/commandlineparser.cpp | 170 | ||||
-rw-r--r-- | src/libs/installer/commandlineparser.h (renamed from src/sdk/commandlineparser.h) | 4 | ||||
-rw-r--r-- | src/libs/installer/commandlineparser_p.cpp | 33 | ||||
-rw-r--r-- | src/libs/installer/commandlineparser_p.h | 48 | ||||
-rw-r--r-- | src/libs/installer/constants.h | 72 | ||||
-rw-r--r-- | src/libs/installer/installer.pro | 8 | ||||
-rw-r--r-- | src/libs/installer/packagemanagercore.cpp | 2 | ||||
-rw-r--r-- | src/sdk/commandlineinterface.cpp | 74 | ||||
-rw-r--r-- | src/sdk/commandlineinterface.h | 8 | ||||
-rw-r--r-- | src/sdk/commandlineparser.cpp | 154 | ||||
-rw-r--r-- | src/sdk/main.cpp | 75 | ||||
-rw-r--r-- | src/sdk/sdk.pro | 6 | ||||
-rw-r--r-- | src/sdk/sdkapp.h | 16 |
13 files changed, 385 insertions, 285 deletions
diff --git a/src/libs/installer/commandlineparser.cpp b/src/libs/installer/commandlineparser.cpp new file mode 100644 index 000000000..0a5ce94de --- /dev/null +++ b/src/libs/installer/commandlineparser.cpp @@ -0,0 +1,170 @@ +/************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "commandlineparser.h" + +#include "constants.h" +#include "globals.h" + +namespace CommandLineOptions { + +const char Command[] = "Command"; +const char Arguments[] = "Args"; +const char InstallerValue[] = "InstallerValue"; + +} // namespace CommandLineOptions + +CommandLineParser::CommandLineParser() + : d(new CommandLineParserPrivate()) +{ + static const QString preformatted = QLatin1String("\nCommands:\n") + + QString::fromLatin1("\t%1 - install default or selected packages - <pkg1 pkg2 pkg3...>\n") + .arg(QLatin1String(CommandLineOptions::Install)) + + QString::fromLatin1("\t%1 - show available updates information on maintenance tool\n") + .arg(QLatin1String(CommandLineOptions::CheckUpdates)) + + QString::fromLatin1("\t%1 - update all or selected packages - <pkg1 pkg2 pkg3...>\n") + .arg(QLatin1String(CommandLineOptions::Update)) + + QString::fromLatin1("\t%1 - uninstall packages and their child components - <pkg1 pkg2 pkg3...>\n") + .arg(QLatin1String(CommandLineOptions::Remove)) + + QString::fromLatin1("\t%1 - list currently installed packages\n") + .arg(QLatin1String(CommandLineOptions::List)) + + QString::fromLatin1("\t%1 - search available packages - <regexp>") + .arg(QLatin1String(CommandLineOptions::Search)); + + m_parser.setApplicationDescription(preformatted); + + // Help & version information + m_parser.addHelpOption(); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Version), + QLatin1String("Displays version information."))); + + // Output related options + m_parser.addOption(QCommandLineOption(QStringList() + << QLatin1String(CommandLineOptions::VerboseShort) + << QLatin1String(CommandLineOptions::VerboseLong), + QLatin1String("Verbose mode. Prints out more information."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::LoggingRules), + QLatin1String("Enables logging according to passed rules. Comma separated logging rules " + "have the following syntax: loggingCategory=true/false. Passing empty logging " + "rules enables all logging categories. The following rules enable a single " + "category: ifw.*=false, ifw.category=true. The following logging categories " + "are available:\n") + QInstaller::loggingCategories().join(QLatin1Char('\n')), + QLatin1String("rules"))); + + // Repository management options + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::AddRepository), + QLatin1String("Add a local or remote repository to the list of user defined repositories."), + QLatin1String("URI,..."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::AddTmpRepository), + QLatin1String("Add a local or remote repository to the list of temporary available repositories."), + QLatin1String("URI,..."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::SetTmpRepository), + QLatin1String("Set a local or remote repository as temporary repository, it is the only " + "one used during fetch.\nNote: URI must be prefixed with the protocol, i.e. " + "file:///, https://, http:// or ftp://."), + QLatin1String("URI,..."))); + + // Proxy options + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::SystemProxy), + QLatin1String("Use system proxy on Windows and Linux. This option has no effect on macOS. (Default)"))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::NoProxy), + QLatin1String("Do not use system proxy."))); + + // Starting mode options + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartUpdater), + QLatin1String("Start application in updater mode. This will override the internal " + "marker that is used to distinguish which kind of binary is currently running."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartPackageManager), + QLatin1String("Start application in package manager mode. This will override the internal " + "marker that is used to distinguish which kind of binary is currently running."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartUninstaller), + QLatin1String("Start application in uninstaller mode. This will override the internal " + "marker that is used to distinguish which kind of binary is currently running."))); + + // Misc installation options + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Root), + QLatin1String("Set installation root directory."), + QLatin1String("directory"))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Platform), + QLatin1String("Use the specified platform plugin."), + QLatin1String("plugin"))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::NoForceInstallation), + QLatin1String("Allow deselecting components that are marked as forced."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::NoSizeChecking), + QLatin1String("Disable checking of free space for installation target."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::ShowVirtualComponents), + QLatin1String("Show virtual components in installer and package manager."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::InstallCompressedRepository), + QLatin1String("Installs QBSP or 7z file. The QBSP (Board Support Package) file must be a .7z " + "file which contains a valid repository."), + QLatin1String("URI,..."))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::CreateLocalRepository), + QLatin1String("Create a local repository inside the installation directory. This option " + "has no effect on online installers."))); + + // Developer options + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Script), + QLatin1String("Execute the script given as argument."), + QLatin1String("file"))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartServer), + QLatin1String("Starts the application as headless process waiting for commands to execute. Mode " + "can be DEBUG or PRODUCTION. In DEBUG mode, the option values can be omitted. Note: " + "The server will not shutdown on his own, you need to quit the process by hand."), + QLatin1String("mode, socketname, key"))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartClient), + QLatin1String("Starts the application to debug the client-server communication. If a value is " + "omitted, the client will use a default instead. Note: The server process is not " + "started by the client application in that case, you need to start it on your own."), + QLatin1String("socketname, key"))); + m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::SquishPort), + QLatin1String("Give a port where Squish can connect to. If no port is given, default port 11233 is " + "used. Note: To enable Squish support you first need to build IFW with SQUISH_PATH " + "parameter where SQUISH_PATH is pointing to your Squish installation folder: " + "<path_to_qt>/bin/qmake -r SQUISH_PATH=<pat_to_squish>"), + QLatin1String("port number"))); + + // Custom extension options + m_parser.addOptions(d->extensionsOptions()); + + // Positional arguments + m_parser.addPositionalArgument(QLatin1String(CommandLineOptions::Command), + QLatin1String("Command to be run by installer."), + QLatin1String("command")); + m_parser.addPositionalArgument(QLatin1String(CommandLineOptions::Arguments), + QLatin1String("Extra arguments for command, each separated by space."), + QLatin1String("<args>")); + m_parser.addPositionalArgument(QLatin1String(CommandLineOptions::InstallerValue), + QLatin1String("Key-value pair to be set internally by the framework."), + QLatin1String("<key=value>")); + +} + +CommandLineParser::~CommandLineParser() +{ + delete d; +} diff --git a/src/sdk/commandlineparser.h b/src/libs/installer/commandlineparser.h index fe6f8f8d7..b21091757 100644 --- a/src/sdk/commandlineparser.h +++ b/src/libs/installer/commandlineparser.h @@ -29,12 +29,15 @@ #ifndef COMMANDLINEPARSER_H #define COMMANDLINEPARSER_H +#include "commandlineparser_p.h" + #include <QCommandLineParser> class CommandLineParser { public: CommandLineParser(); + ~CommandLineParser(); QString helpText() const { return m_parser.helpText(); } bool isSet(const QString &option) { return m_parser.isSet(option); } @@ -45,6 +48,7 @@ public: private: QCommandLineParser m_parser; + class CommandLineParserPrivate *const d; }; #endif // COMMANDLINEPARSER_H diff --git a/src/libs/installer/commandlineparser_p.cpp b/src/libs/installer/commandlineparser_p.cpp new file mode 100644 index 000000000..de9ca45dd --- /dev/null +++ b/src/libs/installer/commandlineparser_p.cpp @@ -0,0 +1,33 @@ +/************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "commandlineparser_p.h" + +CommandLineParserPrivate::CommandLineParserPrivate() +{ +} diff --git a/src/libs/installer/commandlineparser_p.h b/src/libs/installer/commandlineparser_p.h new file mode 100644 index 000000000..1c050a389 --- /dev/null +++ b/src/libs/installer/commandlineparser_p.h @@ -0,0 +1,48 @@ +/************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#ifndef COMMANDLINEPARSER_P_H +#define COMMANDLINEPARSER_P_H + +#include <QCommandLineParser> + +class CommandLineParserPrivate +{ +public: + CommandLineParserPrivate(); + + QList<QCommandLineOption> &extensionsOptions() + { + return m_extensionOptions; + } + +private: + QList<QCommandLineOption> m_extensionOptions; +}; + +#endif // COMMANDLINEPARSER_P_H diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h index ad97227dc..1dd36a9b0 100644 --- a/src/libs/installer/constants.h +++ b/src/libs/installer/constants.h @@ -99,49 +99,61 @@ const char scRelocatable[] = "@RELOCATABLE_PATH@"; namespace CommandLineOptions { +// Help & version information const char HelpShort[] = "h"; const char HelpLong[] = "help"; const char Version[] = "version"; -const char FrameworkVersion[] = "framework-version"; + +// Output related options const char VerboseShort[] = "v"; const char VerboseLong[] = "verbose"; -const char Proxy[] = "proxy"; +const char LoggingRules[] = "logging-rules"; + +// Consumer commands +const char Install[] = "install"; +const char CheckUpdates[] = "check-updates"; +const char Update[] = "update"; +const char Remove[] = "remove"; +const char List[] = "list"; +const char Search[] = "search"; + +// Repository management options +const char AddRepository[] = "add-repository"; +const char AddTmpRepository[] = "add-temp-repository"; +const char SetTmpRepository[] = "set-temp-repository"; + +// Proxy options +const char SystemProxy[] = "system-proxy"; const char NoProxy[] = "no-proxy"; -const char Script[] = "script"; -const char CheckUpdates[] = "checkupdates"; -const char Updater[] = "updater"; -const char ManagePackages[] = "manage-packages"; -const char Uninstaller[] = "uninstaller"; + +// Starting mode options +const char StartUpdater[] = "start-updater"; +const char StartPackageManager[] = "start-package-manager"; +const char StartUninstaller[] = "start-uninstaller"; + +// Misc installation options +const char Root[] = "root"; +const char Platform[] = "platform"; const char NoForceInstallation[] = "no-force-installations"; const char NoSizeChecking[] = "no-size-checking"; const char ShowVirtualComponents[] = "show-virtual-components"; -const char LoggingRules[] = "logging-rules"; +const char InstallCompressedRepository[] = "install-compressed-repository"; const char CreateLocalRepository[] = "create-local-repository"; -const char AddRepository[] = "addRepository"; -const char AddTmpRepository[] = "addTempRepository"; -const char SetTmpRepository[] = "setTempRepository"; -const char StartServer[] = "startserver"; -const char StartClient[] = "startclient"; -const char InstallCompressedRepository[] = "installCompressedRepository"; -const char SilentUpdate[] = "silentUpdate"; -const char UpdatePackages[] = "updatePackages"; -const char ListInstalledPackages[] = "listInstalledPackages"; -const char ListPackages[] = "listPackages"; -const char InstallPackages[] = "installPackages"; -const char InstallDefault[] = "installDefault"; -const char TargetDir[] = "targetDir"; -const char UninstallSelectedPackages[] = "uninstallPackages"; -const char Platform[] = "platform"; + +// Developer options +const char Script[] = "script"; +const char StartServer[] = "start-server"; +const char StartClient[] = "start-client"; const char SquishPort[] = "squish-port"; +// Options supposed to be used without graphical interface static const QStringList scCommandLineInterfaceOptions = { - QLatin1String(ListInstalledPackages), - QLatin1String(ListPackages), - QLatin1String(UpdatePackages), - QLatin1String(InstallPackages), - QLatin1String(InstallDefault), - QLatin1String(UninstallSelectedPackages), - QLatin1String(CheckUpdates) + QLatin1String(Install), + QLatin1String(CheckUpdates), + QLatin1String(Update), + QLatin1String(Remove), + QLatin1String(List), + QLatin1String(Search) }; } // namespace CommandLineOptions diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro index a6dfbde50..2cfb079f5 100644 --- a/src/libs/installer/installer.pro +++ b/src/libs/installer/installer.pro @@ -23,6 +23,7 @@ HEADERS += productkeycheck.h include($$PRODUCTKEYCHECK_PRI_FILE) } else { SOURCES += productkeycheck.cpp + SOURCES += commandlineparser_p.cpp } DESTDIR = $$IFW_LIB_PATH @@ -133,7 +134,9 @@ HEADERS += packagemanagercore.h \ lib7z_extract.h \ lib7z_list.h \ repositorycategory.h \ - componentselectionpage_p.h + componentselectionpage_p.h \ + commandlineparser.h \ + commandlineparser_p.h SOURCES += packagemanagercore.cpp \ packagemanagercore_p.cpp \ @@ -210,7 +213,8 @@ SOURCES += packagemanagercore.cpp \ systeminfo.cpp \ packagesource.cpp \ repositorycategory.cpp \ - componentselectionpage_p.cpp + componentselectionpage_p.cpp \ + commandlineparser.cpp FORMS += proxycredentialsdialog.ui \ serverauthenticationdialog.ui diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 8a0ee2585..4fba56978 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -2008,6 +2008,8 @@ ComponentModel *PackageManagerCore::updaterComponentModel() const void PackageManagerCore::listAvailablePackages(const QString ®exp) { + qCDebug(QInstaller::lcInstallerInstallLog) + << "Searching packages with regular expression:" << regexp; d->fetchMetaInformationFromRepositories(DownloadType::UpdatesXML); d->addUpdateResourcesFromRepositories(true); diff --git a/src/sdk/commandlineinterface.cpp b/src/sdk/commandlineinterface.cpp index c7c02bf96..c5b829084 100644 --- a/src/sdk/commandlineinterface.cpp +++ b/src/sdk/commandlineinterface.cpp @@ -53,6 +53,14 @@ bool CommandLineInterface::initialize() qCWarning(QInstaller::lcInstallerInstallLog) << errorMessage; return false; } + // Filter the arguments list by removing the command itself + // and any key=value pair occurrences. + m_positionalArguments = m_parser.positionalArguments(); + m_positionalArguments.removeFirst(); + foreach (const QString &argument, m_positionalArguments) { + if (argument.contains(QLatin1Char('='))) + m_positionalArguments.removeOne(argument); + } return true; } @@ -93,20 +101,6 @@ int CommandLineInterface::checkUpdates() return EXIT_SUCCESS; } -int CommandLineInterface::silentUpdate() -{ - if (!initialize()) - return EXIT_FAILURE; - if (m_core->isInstaller()) { - qCWarning(QInstaller::lcInstallerInstallLog) << "Cannot perform update with installer."; - return EXIT_FAILURE; - } - if (!checkLicense()) - return EXIT_FAILURE; - m_core->updateComponentsSilently(QStringList()); - return EXIT_SUCCESS; -} - int CommandLineInterface::listInstalledPackages() { if (!initialize()) @@ -120,7 +114,7 @@ int CommandLineInterface::listInstalledPackages() return EXIT_SUCCESS; } -int CommandLineInterface::listAvailablePackages() +int CommandLineInterface::searchAvailablePackages() { if (!initialize()) return EXIT_FAILURE; @@ -128,7 +122,9 @@ int CommandLineInterface::listAvailablePackages() m_core->setPackageManager(); if (!checkLicense()) return EXIT_FAILURE; - QString regexp = m_parser.value(QLatin1String(CommandLineOptions::ListPackages)); + QString regexp; + if (!m_positionalArguments.isEmpty()) + regexp = m_positionalArguments.first(); m_core->listAvailablePackages(regexp); return EXIT_SUCCESS; } @@ -143,37 +139,25 @@ int CommandLineInterface::updatePackages() } if (!checkLicense()) return EXIT_FAILURE; - QStringList packages; - const QString &value = m_parser.value(QLatin1String(CommandLineOptions::UpdatePackages)); - if (!value.isEmpty()) - packages = value.split(QLatin1Char(','), QString::SkipEmptyParts); - m_core->updateComponentsSilently(packages); + m_core->updateComponentsSilently(m_positionalArguments); return EXIT_SUCCESS; } -int CommandLineInterface::install() +int CommandLineInterface::installPackages() { if (!initialize() || (m_core->isInstaller() && !setTargetDir()) || !checkLicense()) return EXIT_FAILURE; - QStringList packages; - const QString &value = m_parser.value(QLatin1String(CommandLineOptions::InstallPackages)); - if (!value.isEmpty()) - packages = value.split(QLatin1Char(','), QString::SkipEmptyParts); - m_core->installSelectedComponentsSilently(packages); - return EXIT_SUCCESS; -} - -int CommandLineInterface::installDefault() -{ - if (!initialize()) - return EXIT_FAILURE; - if (!m_core->isInstaller()) { - qCWarning(QInstaller::lcInstallerInstallLog) << "Cannot perform default installation with maintenance tool."; - return EXIT_FAILURE; + if (m_positionalArguments.isEmpty()) { + if (!m_core->isInstaller()) { + qCWarning(QInstaller::lcInstallerInstallLog) + << "Cannot perform default installation with maintenance tool."; + return EXIT_FAILURE; + } + // No packages provided, install default components + m_core->installDefaultComponentsSilently(); + return EXIT_SUCCESS; } - if (!setTargetDir() || !checkLicense()) - return EXIT_FAILURE; - m_core->installDefaultComponentsSilently(); + m_core->installSelectedComponentsSilently(m_positionalArguments); return EXIT_SUCCESS; } @@ -186,11 +170,7 @@ int CommandLineInterface::uninstallPackages() return EXIT_FAILURE; } m_core->setPackageManager(); - QStringList packages; - const QString &value = m_parser.value(QLatin1String(CommandLineOptions::UninstallSelectedPackages)); - if (!value.isEmpty()) - packages = value.split(QLatin1Char(','), QString::SkipEmptyParts); - m_core->uninstallComponentsSilently(packages); + m_core->uninstallComponentsSilently(m_positionalArguments); return EXIT_SUCCESS; } @@ -207,8 +187,8 @@ bool CommandLineInterface::checkLicense() bool CommandLineInterface::setTargetDir() { QString targetDir; - if (m_parser.isSet(QLatin1String(CommandLineOptions::TargetDir))) { - targetDir = m_parser.value(QLatin1String(CommandLineOptions::TargetDir)); + if (m_parser.isSet(QLatin1String(CommandLineOptions::Root))) { + targetDir = m_parser.value(QLatin1String(CommandLineOptions::Root)); } else { targetDir = m_core->value(QLatin1String("TargetDir")); qCDebug(QInstaller::lcInstallerInstallLog) << "No target directory specified, using default value:" << targetDir; diff --git a/src/sdk/commandlineinterface.h b/src/sdk/commandlineinterface.h index d68c5fc31..efdbb54c8 100644 --- a/src/sdk/commandlineinterface.h +++ b/src/sdk/commandlineinterface.h @@ -39,18 +39,18 @@ class CommandLineInterface : public SDKApp<QCoreApplication> public: CommandLineInterface(int &argc, char *argv[]); int checkUpdates(); - int silentUpdate(); int listInstalledPackages(); - int listAvailablePackages(); + int searchAvailablePackages(); int updatePackages(); - int install(); - int installDefault(); + int installPackages(); int uninstallPackages(); private: bool initialize(); bool checkLicense(); bool setTargetDir(); + + QStringList m_positionalArguments; }; #endif // COMMANDLINEINTERFACE_H diff --git a/src/sdk/commandlineparser.cpp b/src/sdk/commandlineparser.cpp deleted file mode 100644 index dc9371216..000000000 --- a/src/sdk/commandlineparser.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#include "commandlineparser.h" - -#include "constants.h" -#include "globals.h" - -namespace CommandLineOptions { -const char KeyValue[] = "Key=Value"; -} // namespace CommandLineOptions - -CommandLineParser::CommandLineParser() -{ - m_parser.addHelpOption(); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Version), - QLatin1String("Displays version information."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::FrameworkVersion), - QLatin1String("Displays the version of the Qt Installer Framework."))); - - m_parser.addOption(QCommandLineOption(QStringList() - << QLatin1String(CommandLineOptions::VerboseShort) - << QLatin1String(CommandLineOptions::VerboseLong), - QLatin1String("Verbose mode. Prints out more information."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Proxy), - QLatin1String("Use system proxy on Windows and Linux. This option has no effect on macOS."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::NoProxy), - QLatin1String("Do not use system proxy."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Script), - QLatin1String("Execute the script given as argument."), QLatin1String("file"))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::CheckUpdates), - QLatin1String("Check for updates and return an XML description."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Updater), - QLatin1String("Start application in updater mode."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::ManagePackages), - QLatin1String("Start application in package manager mode."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Uninstaller), - QLatin1String("Start application in uninstaller mode."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::NoForceInstallation), - QLatin1String("Allow deselecting components that are marked as forced."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::NoSizeChecking), - QLatin1String("Disable checking of free space for installation target."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::ShowVirtualComponents), - QLatin1String("Show virtual components in installer and package manager."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::LoggingRules), - QLatin1String("Enables logging according to passed rules. " - "Comma separated logging rules have the following syntax: " - "loggingCategory=true/false. " - "Passing empty logging rules enables all logging categories. " - "The following rules enable a single category: " - "ifw.*=false,ifw.category=true " - "The following logging categories are available:\n") - + QInstaller::loggingCategories().join(QLatin1Char('\n')), - QLatin1String("rules"))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::CreateLocalRepository), - QLatin1String("Create a local repository inside the installation directory. This option " - "has no effect on online installers."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::AddRepository), - QLatin1String("Add a local or remote repository to the list of user defined repositories."), - QLatin1String("URI,..."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::AddTmpRepository), - QLatin1String("Add a local or remote repository to the list of temporary available " - "repositories."), QLatin1String("URI,..."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::SetTmpRepository), - QLatin1String("Set a local or remote repository as temporary repository, it is the only " - "one used during fetch.\nNote: URI must be prefixed with the protocol, i.e. file:///, " - "https://, http:// or ftp://."), QLatin1String("URI,..."))); - - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartServer), - QLatin1String("Starts the application as headless process waiting for commands to execute." - " Mode can be DEBUG or PRODUCTION. In DEBUG mode, the option values can be omitted." - "Note: The server will not shutdown on his own, you need to quit the process by hand."), - QLatin1String("mode,socketname,key"))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartClient), - QString::fromLatin1("Starts the application to debug the client-server communication. If " - "a value is omitted, the client will use a default instead. Note: The server process is " - "not started by the client application in that case, you need to start it on your own."), - QLatin1String("socketname,key"))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::InstallCompressedRepository), - QLatin1String("Installs QBSP or 7z file. The QBSP (Board Support Package) file must be a .7z " - "file which contains a valid repository."), - QLatin1String("URI,..."))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::SilentUpdate), - QLatin1String("Updates all packages silently."))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::UpdatePackages), - QLatin1String("Updates selected packages."), QLatin1String("package,..."))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::ListInstalledPackages), - QLatin1String("Lists installed packages."))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::ListPackages), - QLatin1String("Lists available packages."), QLatin1String("regexp"))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::InstallPackages), - QLatin1String("Install selected packages"), - QLatin1String("package,..."))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::InstallDefault), - QLatin1String("Install packages that are checked by default."))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::UninstallSelectedPackages), - QLatin1String("Uninstall selected packages. Note that all child components will be uninstalled as well"), - QLatin1String("package,..."))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::Platform), - QLatin1String("Use the specified platform plugin."), QLatin1String("plugin"))); - m_parser.addPositionalArgument(QLatin1String(CommandLineOptions::KeyValue), - QLatin1String("Key Value pair to be set.")); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::TargetDir), - QLatin1String("Set install directory"), - QLatin1String("directory"))); - m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::SquishPort), - QLatin1String("Give a port where Squish can connect to. If no port is given, default " - "port 11233 is used. Note: To enable Squish support you first need to build IFW with " - "SQUISH_PATH parameter where SQUISH_PATH is pointing to your Squish installation folder: " - "<path_to_qt>/bin/qmake -r SQUISH_PATH=<pat_to_squish>"), - QLatin1String("port number"))); -} diff --git a/src/sdk/main.cpp b/src/sdk/main.cpp index 5ce0615c7..19462fdf5 100644 --- a/src/sdk/main.cpp +++ b/src/sdk/main.cpp @@ -82,22 +82,37 @@ int main(int argc, char *argv[]) CommandLineParser parser; parser.parse(QInstaller::parseCommandLineArgs(argc, argv)); - QStringList mutually; - if (parser.isSet(QLatin1String(CommandLineOptions::CheckUpdates))) - mutually << QLatin1String(CommandLineOptions::CheckUpdates); - if (parser.isSet(QLatin1String(CommandLineOptions::Updater))) - mutually << QLatin1String(CommandLineOptions::Updater); - if (parser.isSet(QLatin1String(CommandLineOptions::ManagePackages))) - mutually << QLatin1String(CommandLineOptions::ManagePackages); - if (parser.isSet(QLatin1String(CommandLineOptions::Uninstaller))) - mutually << QLatin1String(CommandLineOptions::Uninstaller); + bool sanityCheck = true; + QString sanityMessage; + QStringList mutually; + if (parser.isSet(QLatin1String(CommandLineOptions::StartUpdater))) + mutually << QLatin1String(CommandLineOptions::StartUpdater); + if (parser.isSet(QLatin1String(CommandLineOptions::StartPackageManager))) + mutually << QLatin1String(CommandLineOptions::StartPackageManager); + if (parser.isSet(QLatin1String(CommandLineOptions::StartUninstaller))) + mutually << QLatin1String(CommandLineOptions::StartUninstaller); + + if (mutually.count() > 1) { + sanityMessage = QString::fromLatin1("The following options are mutually exclusive: %1.") + .arg(mutually.join(QLatin1String(", "))); + sanityCheck = false; + } + const QSet<QString> commands = parser.positionalArguments().toSet() + .intersect(CommandLineOptions::scCommandLineInterfaceOptions.toSet()); + // Check sanity of the given argument sequence. + if (commands.size() > 1) { + sanityMessage = QString::fromLatin1("%1 commands provided, only one can be used at a time.") + .arg(commands.size()); + sanityCheck = false; + } else if (!commands.isEmpty() && parser.positionalArguments().indexOf(commands.values().first()) != 0) { + sanityMessage = QString::fromLatin1("Found command but it is not given as the first positional " + "argument. \"%1\" given.").arg(parser.positionalArguments().first()); + sanityCheck = false; + } const bool help = parser.isSet(QLatin1String(CommandLineOptions::HelpShort)) || parser.isSet(QLatin1String(CommandLineOptions::HelpLong)); - if (help - || parser.isSet(QLatin1String(CommandLineOptions::Version)) - || parser.isSet(QLatin1String(CommandLineOptions::FrameworkVersion)) - || mutually.count() > 1) { + if (help || parser.isSet(QLatin1String(CommandLineOptions::Version)) || !sanityCheck) { Console c; QCoreApplication app(argc, argv); @@ -110,15 +125,9 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } - if (parser.isSet(QLatin1String(CommandLineOptions::FrameworkVersion))) { - std::cout << QUOTE(IFW_VERSION_STR) << std::endl; - return EXIT_SUCCESS; - } - std::cout << qPrintable(parser.helpText()) << std::endl; - if (mutually.count() > 1) { - std::cerr << qPrintable(QString::fromLatin1("The following options are mutually " - "exclusive: %1.").arg(mutually.join(QLatin1String(", ")))) << std::endl; + if (!sanityCheck) { + std::cerr << qPrintable(sanityMessage) << std::endl; } return help ? EXIT_SUCCESS : EXIT_FAILURE; } @@ -194,7 +203,7 @@ int main(int argc, char *argv[]) foreach (const QString &option, CommandLineOptions::scCommandLineInterfaceOptions) { if (setVerbose) break; - setVerbose = parser.isSet(option); + setVerbose = parser.positionalArguments().contains(option); } if (setVerbose) { console.reset(new Console); @@ -208,7 +217,7 @@ int main(int argc, char *argv[]) std::cerr << "Unknown option: " << qPrintable(options) << std::endl; } - if (parser.isSet(QLatin1String(CommandLineOptions::Proxy))) { + if (parser.isSet(QLatin1String(CommandLineOptions::SystemProxy))) { // Make sure we honor the system's proxy settings QNetworkProxyFactory::setUseSystemConfiguration(true); } @@ -218,21 +227,17 @@ int main(int argc, char *argv[]) const SelfRestarter restarter(argc, argv); - if (parser.isSet(QLatin1String(CommandLineOptions::CheckUpdates))) + if (parser.positionalArguments().contains(QLatin1String(CommandLineOptions::CheckUpdates))) return CommandLineInterface(argc, argv).checkUpdates(); - if (parser.isSet(QLatin1String(CommandLineOptions::SilentUpdate))) - return CommandLineInterface(argc, argv).silentUpdate(); - if (parser.isSet(QLatin1String(CommandLineOptions::ListInstalledPackages))) + if (parser.positionalArguments().contains(QLatin1String(CommandLineOptions::List))) return CommandLineInterface(argc, argv).listInstalledPackages(); - if (parser.isSet(QLatin1String(CommandLineOptions::ListPackages))) - return CommandLineInterface(argc, argv).listAvailablePackages(); - if (parser.isSet(QLatin1String(CommandLineOptions::UpdatePackages))) + if (parser.positionalArguments().contains(QLatin1String(CommandLineOptions::Search))) + return CommandLineInterface(argc, argv).searchAvailablePackages(); + if (parser.positionalArguments().contains(QLatin1String(CommandLineOptions::Update))) return CommandLineInterface(argc, argv).updatePackages(); - if (parser.isSet(QLatin1String(CommandLineOptions::InstallPackages))) - return CommandLineInterface(argc, argv).install(); - if (parser.isSet(QLatin1String(CommandLineOptions::InstallDefault))) - return CommandLineInterface(argc, argv).installDefault(); - if (parser.isSet(QLatin1String(CommandLineOptions::UninstallSelectedPackages))) + if (parser.positionalArguments().contains(QLatin1String(CommandLineOptions::Install))) + return CommandLineInterface(argc, argv).installPackages(); + if (parser.positionalArguments().contains(QLatin1String(CommandLineOptions::Remove))) return CommandLineInterface(argc, argv).uninstallPackages(); if (QInstaller::isVerbose()) diff --git a/src/sdk/sdk.pro b/src/sdk/sdk.pro index 08d08db39..426802892 100644 --- a/src/sdk/sdk.pro +++ b/src/sdk/sdk.pro @@ -101,8 +101,7 @@ HEADERS += \ console.h \ sdkapp.h \ commandlineinterface.h \ - installerbase.h \ - commandlineparser.h + installerbase.h SOURCES = \ main.cpp \ @@ -110,8 +109,7 @@ SOURCES = \ tabcontroller.cpp \ installerbasecommons.cpp \ settingsdialog.cpp \ - commandlineinterface.cpp \ - commandlineparser.cpp + commandlineinterface.cpp win32 { # Use our own manifest file diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h index 12a5aa830..ca52430d2 100644 --- a/src/sdk/sdkapp.h +++ b/src/sdk/sdkapp.h @@ -134,7 +134,7 @@ public: QString loggingRules(QLatin1String("ifw.* = false")); // disable all by default bool isCliInterface = false; foreach (const QString &option, CommandLineOptions::scCommandLineInterfaceOptions) { - if (m_parser.isSet(option)) { + if (m_parser.positionalArguments().contains(option)) { isCliInterface = true; break; } @@ -184,14 +184,12 @@ public: BinaryFormatEngineHandler::instance()->registerResources(manager.collections()); } - // From Qt5.8 onwards a separate command line option --proxy is not needed as system - // proxy is used by default. If Qt is built with QT_USE_SYSTEM_PROXIES false - // then system proxies are not used by default. + // From Qt5.8 onwards system proxy is used by default. If Qt is built with + // QT_USE_SYSTEM_PROXIES false then system proxies are not used by default. if (m_parser.isSet(QLatin1String(CommandLineOptions::NoProxy))) { m_core->settings().setProxyType(QInstaller::Settings::NoProxy); KDUpdater::FileDownloaderFactory::instance().setProxyFactory(m_core->proxyFactory()); - } else if ((m_parser.isSet(QLatin1String(CommandLineOptions::Proxy)) - || QNetworkProxyFactory::usesSystemConfiguration())) { + } else if (QNetworkProxyFactory::usesSystemConfiguration()) { m_core->settings().setProxyType(QInstaller::Settings::SystemProxy); KDUpdater::FileDownloaderFactory::instance().setProxyFactory(m_core->proxyFactory()); } @@ -199,7 +197,7 @@ public: if (m_parser.isSet(QLatin1String(CommandLineOptions::ShowVirtualComponents))) QInstaller::PackageManagerCore::setVirtualComponentsVisible(true); - if (m_parser.isSet(QLatin1String(CommandLineOptions::Updater))) { + if (m_parser.isSet(QLatin1String(CommandLineOptions::StartUpdater))) { if (m_core->isInstaller()) { errorMessage = QObject::tr("Cannot start installer binary as updater."); return false; @@ -207,7 +205,7 @@ public: m_core->setUserSetBinaryMarker(QInstaller::BinaryContent::MagicUpdaterMarker); } - if (m_parser.isSet(QLatin1String(CommandLineOptions::ManagePackages))) { + if (m_parser.isSet(QLatin1String(CommandLineOptions::StartPackageManager))) { if (m_core->isInstaller()) { errorMessage = QObject::tr("Cannot start installer binary as package manager."); return false; @@ -215,7 +213,7 @@ public: m_core->setUserSetBinaryMarker(QInstaller::BinaryContent::MagicPackageManagerMarker); } - if (m_parser.isSet(QLatin1String(CommandLineOptions::Uninstaller))) { + if (m_parser.isSet(QLatin1String(CommandLineOptions::StartUninstaller))) { if (m_core->isInstaller()) { errorMessage = QObject::tr("Cannot start installer binary as uninstaller."); return false; |