summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2023-03-22 15:38:30 +0100
committerRobert Griebl <robert.griebl@qt.io>2023-03-23 14:08:00 +0100
commit6cc5230fd783802159aa3ca94c74b7ee1b27203a (patch)
treecccf37758beb6c93d2b4f584eeb8faf4b98f02b3
parent0ae6d0a3637075fe8005361177eae3142eee0a77 (diff)
downloadqtapplicationmanager-6cc5230fd783802159aa3ca94c74b7ee1b27203a.tar.gz
Make it possible to specify directories to read config files from
This extends the existing -c/--config-file option to also accept directories, effectively expanding the argument to all *.yaml files in the given directory. Change-Id: I83f197e8f67ba363bf27b0f511c7821402bb7033 Pick-to: 5.15 6.5 Reviewed-by: Bernd Weimer <bernd.weimer@qt.io>
-rw-r--r--doc/configuration.qdoc3
-rw-r--r--src/main-lib/configuration.cpp13
-rw-r--r--tests/auto/configuration/tst_configuration.cpp2
3 files changed, 16 insertions, 2 deletions
diff --git a/doc/configuration.qdoc b/doc/configuration.qdoc
index 495794c6..40099c88 100644
--- a/doc/configuration.qdoc
+++ b/doc/configuration.qdoc
@@ -110,6 +110,9 @@ ui:
The application manager saves the result of parsing and evaluating all the
configuration files into a cache. This cache is loaded on subsequent starts, if the
exact set of config files is used, unchanged.
+
+ In case the given argument is a directory, all files with a \c{.yaml} extension will be
+ loaded from that directory in alphabetical order (ASCII sort order, non-recursive).
\row
\li \b --no-cache
\li bool
diff --git a/src/main-lib/configuration.cpp b/src/main-lib/configuration.cpp
index a94e2389..a689595b 100644
--- a/src/main-lib/configuration.cpp
+++ b/src/main-lib/configuration.cpp
@@ -295,7 +295,18 @@ void Configuration::parseWithArguments(const QStringList &arguments)
timer.start();
#endif
- QStringList configFilePaths = m_clp.values(qSL("config-file"));
+ const QStringList rawConfigFilePaths = m_clp.values(qSL("config-file"));
+ QStringList configFilePaths;
+ configFilePaths.reserve(rawConfigFilePaths.size());
+ for (const auto &path : rawConfigFilePaths) {
+ if (QFileInfo(path).isDir()) {
+ const auto entries = QDir(path).entryInfoList({ qSL("*.yaml") }, QDir::Files, QDir::Name);
+ for (const auto &entry : entries)
+ configFilePaths << entry.filePath();
+ } else {
+ configFilePaths << path;
+ }
+ }
AbstractConfigCache::Options cacheOptions = AbstractConfigCache::MergedResult;
if (noCache())
diff --git a/tests/auto/configuration/tst_configuration.cpp b/tests/auto/configuration/tst_configuration.cpp
index 603fca67..dfdd3cad 100644
--- a/tests/auto/configuration/tst_configuration.cpp
+++ b/tests/auto/configuration/tst_configuration.cpp
@@ -247,7 +247,7 @@ void tst_Configuration::simpleConfig()
void tst_Configuration::mergedConfig()
{
- Configuration c({ qSL(":/data/config1.yaml"), qSL(":/data/config2.yaml") }, qSL(":/build-config.yaml"));
+ Configuration c({ qSL(":/data/") }, qSL(":/build-config.yaml"));
c.parseWithArguments({ qSL("test"), qSL("--no-cache") });
QVERIFY(c.noCache());