From 40219833997e6a6be343ac1207d61d16937cc24f Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:49:49 -0800 Subject: [PATCH] Support finding poac.toml in parent directories --- src/Manifest.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Manifest.cc b/src/Manifest.cc index 79457ced1..3487b1c96 100644 --- a/src/Manifest.cc +++ b/src/Manifest.cc @@ -13,6 +13,28 @@ #define TOML11_NO_ERROR_PREFIX #include +static Path findManifest() { + Path candidate = fs::current_path(); + while (true) { + const Path config_path = candidate / "poac.toml"; + Logger::debug("Finding manifest: ", config_path); + if (fs::exists(config_path)) { + return config_path; + } + + const Path parent_path = candidate.parent_path(); + if (candidate.has_parent_path() + && parent_path != candidate.root_directory()) { + candidate = parent_path; + } else { + break; + } + } + + throw std::runtime_error("could not find `poac.toml` here and in its parents" + ); +} + class Manifest { public: static Manifest& instance() noexcept { @@ -32,7 +54,7 @@ class Manifest { toml::color::disable(); } - data = toml::parse("poac.toml"); + data = toml::parse(findManifest()); } Option data = None;