diff options
Diffstat (limited to 'nihil.config/read.cc')
| -rw-r--r-- | nihil.config/read.cc | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/nihil.config/read.cc b/nihil.config/read.cc index 0a5fcad..e7def91 100644 --- a/nihil.config/read.cc +++ b/nihil.config/read.cc @@ -11,15 +11,15 @@ module; #include <iterator> #include <string> +module nihil.config; + import nihil; import nihil.ucl; -module nihil.config; - namespace nihil::config { auto read_from(std::filesystem::path const &filename) - -> std::expected<void, nihil::error> + -> std::expected<void, error> { // TODO: nihil.ucl should have a way to load UCL from a filename. @@ -29,33 +29,20 @@ auto read_from(std::filesystem::path const &filename) // 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) - return {}; + co_return {}; auto errstr = std::format("cannot read {}", filename.string()); - return std::unexpected(nihil::error(errstr, err.error())); + co_return std::unexpected(error(errstr, err.error())); } // Parse the UCL. - try { - auto uclconfig = ucl::parse(config_text); - - for (auto &&[key, value] : uclconfig) { - auto &opt = store::get().fetch(key); - opt.from_ucl(value); - } - } catch (unknown_option const &) { - // This is probably an old option which has been removed; - // ignore it, and we'll remove the bad option next time - // we write the config. - } catch (error const &err) { - // Include the filename in any other config errors. - throw error(std::format("{}: {}", filename.string(), - err.what())); - } catch (ucl::error const &err) { - throw error(std::format("{}: {}", filename.string(), - err.what())); + 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); } - return {}; + co_return {}; } } // namespace nihil::config |
