diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-23 16:28:11 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-23 16:28:11 +0100 |
| commit | d5963532328ce5f1c9f266bf7e760b7d18a60c15 (patch) | |
| tree | 28e8d4b98f2f3adbd2f02bcc656ad74e626677c9 /nihil.config/write.ccm | |
| parent | 0fa623093366351ad47583f47add6e51f56a56d8 (diff) | |
| download | nihil-d5963532328ce5f1c9f266bf7e760b7d18a60c15.tar.gz nihil-d5963532328ce5f1c9f266bf7e760b7d18a60c15.tar.bz2 | |
various updates
Diffstat (limited to 'nihil.config/write.ccm')
| -rw-r--r-- | nihil.config/write.ccm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/nihil.config/write.ccm b/nihil.config/write.ccm new file mode 100644 index 0000000..947c7ee --- /dev/null +++ b/nihil.config/write.ccm @@ -0,0 +1,42 @@ +/* + * This source code is released into the public domain. + */ + +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. + */ +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())); +} + +}; |
