Skip to content

Commit

Permalink
feat(Config): paths relative to secondary options
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Dec 16, 2024
1 parent 49849a5 commit 4bbf7ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/lib/Lib/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string_view> res = Unexpected(formatError("unknown relative-to value: \"{}\"", referenceDirKey));
settings.visit([&]<typename T>(std::string_view const name, T& value)
{
if constexpr (std::convertible_to<T, std::string_view>)
{
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));
}
Expand Down
10 changes: 10 additions & 0 deletions util/generate-config-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@ def generate_public_settings_hpp(config):
contents += f' std::forward<F>(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 <class F>\n'
contents += ' void\n'
contents += ' visit(F&& f) const\n'
contents += ' {\n'
for option in flat_options:
contents += f' std::forward<F>(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
Expand Down

0 comments on commit 4bbf7ec

Please sign in to comment.