diff options
author | Robert Griebl <robert.griebl@qt.io> | 2023-03-22 15:38:30 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-03-23 13:52:48 +0000 |
commit | f894d1c1156520c3fdab84b4ec4e2646375daf1f (patch) | |
tree | 237f3db220812c909ca1f49c38630cd0db1ed9d4 | |
parent | 055184c45eb92c6d70d9653a7963d441b9db2f04 (diff) | |
download | qtapplicationmanager-f894d1c1156520c3fdab84b4ec4e2646375daf1f.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
Reviewed-by: Bernd Weimer <bernd.weimer@qt.io>
(cherry picked from commit 6cc5230fd783802159aa3ca94c74b7ee1b27203a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | doc/configuration.qdoc | 3 | ||||
-rw-r--r-- | src/main-lib/configuration.cpp | 13 | ||||
-rw-r--r-- | tests/auto/configuration/tst_configuration.cpp | 2 |
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()); |