summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2023-09-18 13:13:33 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2023-10-05 16:21:17 +0300
commit7acda96cb33c3f6c9157cd4de0b73be8aff04a92 (patch)
tree95155b9271b9fd22ba96d7c7c639d2835ca6c26e
parent5537fbec2d158549eb1350e72600ac2d577ab145 (diff)
CLI: adjust 'search' command behavior with --type option
In case the "--type=aliases|packages" option is omitted, search first for aliases, and if not found, search for components. If the option is specified, search only given type. This changes the behavior from previous one, where only aliases were considered for the search by default, if the type option was omitted. Change-Id: Ie01ea85e1b88376f8df3edbf864d1e78788c3464 Reviewed-by: Iikka Eklund <iikka.eklund@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r--doc/installerfw-using.qdoc22
-rw-r--r--src/libs/installer/commandlineparser.cpp3
-rw-r--r--src/libs/installer/packagemanagercore.cpp93
-rw-r--r--src/libs/installer/packagemanagercore.h4
-rw-r--r--src/sdk/commandlineinterface.cpp16
-rw-r--r--tests/auto/installer/commandlineinstall/tst_commandlineinstall.cpp2
6 files changed, 88 insertions, 52 deletions
diff --git a/doc/installerfw-using.qdoc b/doc/installerfw-using.qdoc
index c1a57f9ad..e6e2a3111 100644
--- a/doc/installerfw-using.qdoc
+++ b/doc/installerfw-using.qdoc
@@ -463,21 +463,33 @@
The \c search command can be used to search components from available repositories, or
from integrated binary content in case of an offline installer. It can be used with
no arguments to list all available components or with a regular expression to get a list
- of only components matching the pattern. The \c --filter-packages option can be
- used to specify additional filters for the search operation. For a list of usable
- information elements with the option, refer to \l{Summary of Package Information File Elements}.
+ of only components matching the pattern.
+
+ The \c --filter-packages option can be used to specify additional filters for the search
+ operation. For a list of usable information elements with the option, refer to
+ \l{Summary of Package Information File Elements}.
+
+ When the value of the \c{--type} option is set to \c package, the search command will
+ search for available components only:
\code
installer.exe --type package --filter-packages "DisplayName=MyComponent, Version=1.0" search "expression"
\endcode
- When the \c{--type} option is omitted, or the value for the option is set to \c alias, the
- search command will seach for available component aliases instead:
+ When the \c{--type} option is omitted, the search command will first search for matching
+ component aliases, and if none are found, component names:
\code
installer.exe search "expression"
\endcode
+ When the value of the \c{--type} option is set to \c alias, the search command will
+ search for available component aliases only:
+
+ \code
+ installer.exe --type alias search "expression"
+ \endcode
+
\section1 Performing Full Uninstallation
To uninstall all components and remove the program directory, including maintenance tool,
diff --git a/src/libs/installer/commandlineparser.cpp b/src/libs/installer/commandlineparser.cpp
index 94b611334..f9e1f663e 100644
--- a/src/libs/installer/commandlineparser.cpp
+++ b/src/libs/installer/commandlineparser.cpp
@@ -183,7 +183,8 @@ CommandLineParser::CommandLineParser()
addOption(QCommandLineOption(QStringList()
<< CommandLineOptions::scTypeLong,
QLatin1String("[CLI] Sets the type of the given arguments for commands supporting multiple argument types, "
- "like \"search\". Defaults to \"alias\"."),
+ "like \"search\". By default aliases are searched first, and if no matching aliases are found, "
+ "then packages are searched with the same search pattern."),
QLatin1String("package|alias")));
// Message query options
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 62852a682..6b409a778 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -2506,12 +2506,13 @@ ComponentModel *PackageManagerCore::defaultComponentModel() const
if (!d->m_defaultModel) {
d->m_defaultModel = componentModel(const_cast<PackageManagerCore*> (this),
QLatin1String("AllComponentsModel"));
+
+ connect(this, &PackageManagerCore::startAllComponentsReset, [&] {
+ d->m_defaultModel->reset();
+ });
+ connect(this, &PackageManagerCore::finishAllComponentsReset, d->m_defaultModel,
+ &ComponentModel::reset);
}
- connect(this, &PackageManagerCore::startAllComponentsReset, [&] {
- d->m_defaultModel->reset();
- });
- connect(this, &PackageManagerCore::finishAllComponentsReset, d->m_defaultModel,
- &ComponentModel::reset);
return d->m_defaultModel;
}
@@ -2524,12 +2525,13 @@ ComponentModel *PackageManagerCore::updaterComponentModel() const
if (!d->m_updaterModel) {
d->m_updaterModel = componentModel(const_cast<PackageManagerCore*> (this),
QLatin1String("UpdaterComponentsModel"));
+
+ connect(this, &PackageManagerCore::startUpdaterComponentsReset, [&] {
+ d->m_updaterModel->reset();
+ });
+ connect(this, &PackageManagerCore::finishUpdaterComponentsReset, d->m_updaterModel,
+ &ComponentModel::reset);
}
- connect(this, &PackageManagerCore::startUpdaterComponentsReset, [&] {
- d->m_updaterModel->reset();
- });
- connect(this, &PackageManagerCore::finishUpdaterComponentsReset, d->m_updaterModel,
- &ComponentModel::reset);
return d->m_updaterModel;
}
@@ -2539,29 +2541,39 @@ ComponentModel *PackageManagerCore::updaterComponentModel() const
hash containing package information elements and regular expressions
can be used to further filter listed packages.
+ Returns \c true if matching packages were found, \c false otherwise.
+
\sa setVirtualComponentsVisible()
*/
-void PackageManagerCore::listAvailablePackages(const QString &regexp, const QHash<QString, QString> &filters)
+bool PackageManagerCore::listAvailablePackages(const QString &regexp, const QHash<QString, QString> &filters)
{
setPackageViewer();
qCDebug(QInstaller::lcInstallerInstallLog)
<< "Searching packages with regular expression:" << regexp;
ComponentModel *model = defaultComponentModel();
- d->fetchMetaInformationFromRepositories();
+ PackagesList packages;
+
+ if (!d->m_updates) {
+ d->fetchMetaInformationFromRepositories();
+ d->addUpdateResourcesFromRepositories();
+
+ packages = d->remotePackages();
+ if (!fetchAllPackages(packages, LocalPackagesMap())) {
+ qCWarning(QInstaller::lcInstallerInstallLog)
+ << "There was a problem with loading the package data.";
+ return false;
+ }
+ } else {
+ // No need to fetch metadata again
+ packages = d->remotePackages();
+ }
- d->addUpdateResourcesFromRepositories();
QRegularExpression re(regexp);
re.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
- const PackagesList &packages = d->remotePackages();
- if (!fetchAllPackages(packages, LocalPackagesMap())) {
- qCWarning(QInstaller::lcInstallerInstallLog)
- << "There was a problem with loading the package data.";
- return;
- }
PackagesList matchedPackages;
- foreach (Package *package, packages) {
+ foreach (Package *package, qAsConst(packages)) {
const QString name = package->data(scName).toString();
Component *component = componentByName(name);
if (!component)
@@ -2583,19 +2595,24 @@ void PackageManagerCore::listAvailablePackages(const QString &regexp, const QHas
matchedPackages.append(package);
}
}
- if (matchedPackages.count() == 0)
+ if (matchedPackages.count() == 0) {
qCDebug(QInstaller::lcInstallerInstallLog) << "No matching packages found.";
- else
- LoggingHandler::instance().printPackageInformation(matchedPackages, localInstalledPackages());
+ return false;
+ }
+
+ LoggingHandler::instance().printPackageInformation(matchedPackages, localInstalledPackages());
+ return true;
}
/*!
Lists available component aliases filtered with \a regexp without GUI. Virtual
aliases are not listed unless set visible.
+ Returns \c true if matching package aliases were found, \c false otherwise.
+
\sa setVirtualComponentsVisible()
*/
-void PackageManagerCore::listAvailableAliases(const QString &regexp)
+bool PackageManagerCore::listAvailableAliases(const QString &regexp)
{
setPackageViewer();
qCDebug(QInstaller::lcInstallerInstallLog)
@@ -2604,17 +2621,20 @@ void PackageManagerCore::listAvailableAliases(const QString &regexp)
ComponentModel *model = defaultComponentModel();
Q_UNUSED(model);
- d->fetchMetaInformationFromRepositories();
- d->addUpdateResourcesFromRepositories();
+ if (!d->m_updates) {
+ d->fetchMetaInformationFromRepositories();
+ d->addUpdateResourcesFromRepositories();
+
+ const PackagesList &packages = d->remotePackages();
+ if (!fetchAllPackages(packages, LocalPackagesMap())) {
+ qCWarning(QInstaller::lcInstallerInstallLog)
+ << "There was a problem with loading the package data.";
+ return false;
+ }
+ }
QRegularExpression re(regexp);
re.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
- const PackagesList &packages = d->remotePackages();
- if (!fetchAllPackages(packages, LocalPackagesMap())) {
- qCWarning(QInstaller::lcInstallerInstallLog)
- << "There was a problem with loading the package data.";
- return;
- }
QList<ComponentAlias *> matchedAliases;
for (auto *alias : qAsConst(d->m_componentAliases)) {
@@ -2629,10 +2649,13 @@ void PackageManagerCore::listAvailableAliases(const QString &regexp)
}
}
- if (matchedAliases.isEmpty())
+ if (matchedAliases.isEmpty()) {
qCDebug(QInstaller::lcInstallerInstallLog) << "No matching package aliases found.";
- else
- LoggingHandler::instance().printAliasInformation(matchedAliases);
+ return false;
+ }
+
+ LoggingHandler::instance().printAliasInformation(matchedAliases);
+ return true;
}
bool PackageManagerCore::componentUninstallableFromCommandLine(const QString &componentName)
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 10df10377..74d45007f 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -275,9 +275,9 @@ public:
ComponentModel *updaterComponentModel() const;
void listInstalledPackages(const QString &regexp = QString());
- void listAvailablePackages(const QString &regexp = QString(),
+ bool listAvailablePackages(const QString &regexp = QString(),
const QHash<QString, QString> &filters = QHash<QString, QString>());
- void listAvailableAliases(const QString &regexp = QString());
+ bool listAvailableAliases(const QString &regexp = QString());
PackageManagerCore::Status updateComponentsSilently(const QStringList &componentsToUpdate);
PackageManagerCore::Status installSelectedComponentsSilently(const QStringList& components);
diff --git a/src/sdk/commandlineinterface.cpp b/src/sdk/commandlineinterface.cpp
index 710fb8a97..673744c8e 100644
--- a/src/sdk/commandlineinterface.cpp
+++ b/src/sdk/commandlineinterface.cpp
@@ -140,15 +140,17 @@ int CommandLineInterface::searchAvailablePackages()
if (!m_positionalArguments.isEmpty())
regexp = m_positionalArguments.first();
- bool searchAliases = true;
if (m_parser.isSet(CommandLineOptions::scTypeLong)) {
- searchAliases = (m_parser.value(CommandLineOptions::scTypeLong)
- != QLatin1String("packages"));
+ // If type is specified, only list relevant contents
+ if (m_parser.value(CommandLineOptions::scTypeLong) == QLatin1String("package"))
+ m_core->listAvailablePackages(regexp, parsePackageFilters());
+ else if (m_parser.value(CommandLineOptions::scTypeLong) == QLatin1String("alias"))
+ m_core->listAvailableAliases(regexp);
+ } else {
+ // No type - we can try again with packages search if there were no matching aliases
+ if (!m_core->listAvailableAliases(regexp))
+ m_core->listAvailablePackages(regexp, parsePackageFilters());
}
- if (searchAliases)
- m_core->listAvailableAliases(regexp);
- else
- m_core->listAvailablePackages(regexp, parsePackageFilters());
return EXIT_SUCCESS;
}
diff --git a/tests/auto/installer/commandlineinstall/tst_commandlineinstall.cpp b/tests/auto/installer/commandlineinstall/tst_commandlineinstall.cpp
index 1da28865a..948768f8d 100644
--- a/tests/auto/installer/commandlineinstall/tst_commandlineinstall.cpp
+++ b/tests/auto/installer/commandlineinstall/tst_commandlineinstall.cpp
@@ -48,8 +48,6 @@ public:
void ignoreAvailablePackagesMissingMessages()
{
QTest::ignoreMessage(QtDebugMsg, QRegularExpression("Searching packages with regular expression:"));
- QTest::ignoreMessage(QtDebugMsg, "Fetching latest update information...");
- QTest::ignoreMessage(QtDebugMsg, "Loading component scripts...");
QTest::ignoreMessage(QtDebugMsg, "No matching packages found.");
}