#pragma once #include #include #include #include #include #include namespace Void::Configuration { /// Look up a single environment variable by name. /// Returns an error if the variable is not set. [[nodiscard]] inline Void::Result::Result get_env(std::string_view name) { std::string name_str{name}; const char* val = std::getenv(name_str.c_str()); // NOLINT(concurrency-mt-unsafe) if (!val) { return Void::Result::fail( std::format("Configuration::get_env: '{}' is not set", name)); } return Void::Result::ok(std::string{val}); } /// Look up a single environment variable, returning `fallback` if not set. [[nodiscard]] inline std::string get_env_or(std::string_view name, std::string_view fallback = {}) { std::string name_str{name}; const char* val = std::getenv(name_str.c_str()); // NOLINT(concurrency-mt-unsafe) return val ? std::string{val} : std::string{fallback}; } } // namespace Void::Configuration