aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.config/write.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-23 19:45:54 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-23 19:45:54 +0100
commit2a3f19ff67bd0292a2812993b2b19c292d113959 (patch)
tree81fa477e6c1470f77a3ddd12ee5804c7a315f2c3 /nihil.config/write.ccm
parent504c02086832dcaab5cfa042ee7a488470284424 (diff)
downloadnihil-2a3f19ff67bd0292a2812993b2b19c292d113959.tar.gz
nihil-2a3f19ff67bd0292a2812993b2b19c292d113959.tar.bz2
config: add separate implementation for read, write
Diffstat (limited to 'nihil.config/write.ccm')
-rw-r--r--nihil.config/write.ccm29
1 files changed, 3 insertions, 26 deletions
diff --git a/nihil.config/write.ccm b/nihil.config/write.ccm
index 947c7ee..71cdbb3 100644
--- a/nihil.config/write.ccm
+++ b/nihil.config/write.ccm
@@ -5,38 +5,15 @@
module;
#include <filesystem>
-#include <format>
-#include <utility>
export module nihil.config:write;
-import nihil.ucl;
-import :store;
-
namespace nihil::config {
/*
- * Write all config values (except defaults) to disk.
+ * Write all config values (except defaults) to disk. Throws config::error
+ * on failure.
*/
-auto write_to(std::filesystem::path const &filename) -> void
-try {
- auto uclconfig = ucl::map<ucl::object>();
-
- // Add all the options to the UCL object.
- for (auto const &option : store::get().all()) {
- if (option.is_default())
- continue;
-
- uclconfig.insert({option.name(), option.to_ucl()});
- }
-
- auto ucl_text = std::format("{:c}", uclconfig);
- auto ret = safe_write_file(filename, ucl_text);
- if (!ret)
- throw error(std::format("{}: {}", filename.string(),
- ret.error().message()));
-} catch (ucl::error const &exc) {
- throw error(std::format("{}: {}", filename.string(), exc.what()));
-}
+auto write_to(std::filesystem::path const &filename) -> void;
};