From 3a002fb9c23fc9a6384bc1b30a8e364924bb574e Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 7 Oct 2025 21:46:03 +0200 Subject: cfg: Make load less magic Don't try to guess from name, instead, have one method for only loading one config from a file (that might be relative) and loading a config from config dirs using a name (that might contain slash). --- src/cfg.cc | 16 +++++++++------- src/cfg.hh | 13 +++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/cfg.cc b/src/cfg.cc index 0196bde..b65246f 100644 --- a/src/cfg.cc +++ b/src/cfg.cc @@ -182,16 +182,18 @@ std::optional Config::get_bool(std::string_view name) const { return std::nullopt; } -std::unique_ptr Config::load(std::string_view name, - std::vector& errors) { - if (name.empty() || name.front() == '/') { - auto ret = std::make_unique(); - ret->load(name, errors); - return ret; - } +std::unique_ptr load_all(std::string_view name, + std::vector& errors) { auto ret = std::make_unique(); ret->load(name, errors); return ret; } +std::unique_ptr load_one(std::filesystem::path const& path, + std::vector& errors) { + auto ret = std::make_unique(); + ret->load(path, errors); + return ret; +} + } // namespace cfg diff --git a/src/cfg.hh b/src/cfg.hh index a4a7865..3be9a00 100644 --- a/src/cfg.hh +++ b/src/cfg.hh @@ -1,6 +1,7 @@ #ifndef CFG_HH #define CFG_HH +#include #include #include #include @@ -24,10 +25,6 @@ class Config { [[nodiscard]] std::optional get_bool(std::string_view name) const; - [[nodiscard]] - static std::unique_ptr load(std::string_view name, - std::vector& errors); - protected: Config() = default; @@ -35,6 +32,14 @@ class Config { Config& operator=(Config const&) = delete; }; +[[nodiscard]] +std::unique_ptr load_all(std::string_view name, + std::vector& errors); + +[[nodiscard]] +std::unique_ptr load_one(std::filesystem::path const& path, + std::vector& errors); + } // namespace cfg #endif // CFG_HH -- cgit v1.2.3-70-g09d2