diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-10-07 21:46:03 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-10-19 00:13:47 +0200 |
| commit | 3a002fb9c23fc9a6384bc1b30a8e364924bb574e (patch) | |
| tree | 7cfb59964bc20bbb14d157426b2aad4481deb90d /src | |
| parent | 62a4abb9bf6551417130c3c6f9bba147930895ef (diff) | |
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).
Diffstat (limited to 'src')
| -rw-r--r-- | src/cfg.cc | 16 | ||||
| -rw-r--r-- | src/cfg.hh | 13 |
2 files changed, 18 insertions, 11 deletions
@@ -182,16 +182,18 @@ std::optional<bool> Config::get_bool(std::string_view name) const { return std::nullopt; } -std::unique_ptr<Config> Config::load(std::string_view name, - std::vector<std::string>& errors) { - if (name.empty() || name.front() == '/') { - auto ret = std::make_unique<ConfigSingleImpl>(); - ret->load(name, errors); - return ret; - } +std::unique_ptr<Config> load_all(std::string_view name, + std::vector<std::string>& errors) { auto ret = std::make_unique<ConfigXdgImpl>(); ret->load(name, errors); return ret; } +std::unique_ptr<Config> load_one(std::filesystem::path const& path, + std::vector<std::string>& errors) { + auto ret = std::make_unique<ConfigSingleImpl>(); + ret->load(path, errors); + return ret; +} + } // namespace cfg @@ -1,6 +1,7 @@ #ifndef CFG_HH #define CFG_HH +#include <filesystem> #include <memory> #include <optional> #include <string_view> @@ -24,10 +25,6 @@ class Config { [[nodiscard]] std::optional<bool> get_bool(std::string_view name) const; - [[nodiscard]] - static std::unique_ptr<Config> load(std::string_view name, - std::vector<std::string>& errors); - protected: Config() = default; @@ -35,6 +32,14 @@ class Config { Config& operator=(Config const&) = delete; }; +[[nodiscard]] +std::unique_ptr<Config> load_all(std::string_view name, + std::vector<std::string>& errors); + +[[nodiscard]] +std::unique_ptr<Config> load_one(std::filesystem::path const& path, + std::vector<std::string>& errors); + } // namespace cfg #endif // CFG_HH |
