From 2e2d1bd3b6c7776b77c33b94f30ead89367a71e6 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Tue, 1 Jul 2025 17:07:04 +0100 Subject: add nihil.std --- nihil.config/read.cc | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 nihil.config/read.cc (limited to 'nihil.config/read.cc') diff --git a/nihil.config/read.cc b/nihil.config/read.cc deleted file mode 100644 index 48484fb..0000000 --- a/nihil.config/read.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This source code is released into the public domain. - */ - -module; - -#include -#include -#include -#include -#include -#include - -module nihil.config; - -import nihil.error; -import nihil.monad; -import nihil.posix; -import nihil.ucl; - -namespace nihil::config { - -auto read_from(std::filesystem::path const &filename) - -> std::expected -{ - // TODO: nihil.ucl should have a way to load UCL from a filename. - - std::string config_text; - auto err = read_file(filename, std::back_inserter(config_text)); - if (!err) { - // Ignore ENOENT, it simply means we haven't created the - // config file yet, so default values will be used. - if (err.error().root_cause() == std::errc::no_such_file_or_directory) - co_return {}; - auto errstr = std::format("cannot read {}", filename.string()); - co_return std::unexpected(error(errstr, err.error())); - } - - // Parse the UCL. - auto uclconfig = co_await ucl::parse(config_text); - - for (auto &&[key, value] : uclconfig) { - auto opt = co_await store::get().fetch(key); - co_await opt->ucl(value); - } - - co_return {}; -} - -} // namespace nihil::config -- cgit v1.2.3