diff options
Diffstat (limited to 'nihil.config/write.cc')
| -rw-r--r-- | nihil.config/write.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/nihil.config/write.cc b/nihil.config/write.cc new file mode 100644 index 0000000..4b2a232 --- /dev/null +++ b/nihil.config/write.cc @@ -0,0 +1,39 @@ +/* + * This source code is released into the public domain. + */ + +module; + +#include <filesystem> +#include <format> +#include <utility> + +import nihil; +import nihil.ucl; + +module nihil.config; + +namespace nihil::config { + +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())); +} + +}; |
