diff --git a/src/lib/Lib/Config.cpp b/src/lib/Lib/Config.cpp index 1e6ad01c6..4cd4b4d9d 100644 --- a/src/lib/Lib/Config.cpp +++ b/src/lib/Lib/Config.cpp @@ -193,15 +193,34 @@ struct PublicSettingsVisitor { if (referenceDirKey == "config-dir") { return dirs.configDir; } - else if (referenceDirKey == "cwd") { + if (referenceDirKey == "cwd") { return dirs.cwd; } - else if (referenceDirKey == "mrdocs-root") { + if (referenceDirKey == "mrdocs-root") { return dirs.mrdocsRoot; } - else if (referenceDirKey == "output") { - MRDOCS_ASSERT(!settings.output.empty()); - return settings.output; + if (!referenceDirKey.empty()) { + Expected res = Unexpected(formatError("unknown relative-to value: \"{}\"", referenceDirKey)); + settings.visit([&](std::string_view const name, T& value) + { + if constexpr (std::convertible_to) + { + if (name != referenceDirKey) + { + return; + } + std::string_view valueSv(value); + if (!value.empty()) + { + res = value; + return; + } + res = Unexpected(formatError( + "relative-to value \"{}\" is empty", + referenceDirKey)); + } + }); + return res; } return Unexpected(formatError("unknown relative-to value: \"{}\"", referenceDirKey)); } diff --git a/util/generate-config-info.py b/util/generate-config-info.py index 8a7361ea8..4bc5f9d97 100644 --- a/util/generate-config-info.py +++ b/util/generate-config-info.py @@ -361,6 +361,16 @@ def generate_public_settings_hpp(config): contents += f' std::forward(f)({escape_as_cpp_string(option["name"])}, {to_camel_case(option["name"])});\n' contents += ' }\n\n' + contents += ' /** Visit all options\n' + contents += ' */\n' + contents += ' template \n' + contents += ' void\n' + contents += ' visit(F&& f) const\n' + contents += ' {\n' + for option in flat_options: + contents += f' std::forward(f)({escape_as_cpp_string(option["name"])}, {to_camel_case(option["name"])});\n' + contents += ' }\n\n' + contents += '}; // struct PublicSettings\n\n' # Functions to convert enums to strings