Skip to content

Commit

Permalink
feat: output base directory support for relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni authored Nov 29, 2024
1 parent 2da68d8 commit af97cfe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/lib/Lib/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct PublicSettingsVisitor {
{
// If the path is not absolute, we need to expand it
if (!files::isAbsolute(value)) {
auto exp = getBaseDir(value, dirs, useDefault, opts);
auto exp = getBaseDir(value, dirs, self, useDefault, opts);
if (!exp)
{
MRDOCS_TRY(value, files::makeAbsolute(value));
Expand Down Expand Up @@ -124,7 +124,7 @@ struct PublicSettingsVisitor {
for (auto& v : value) {
if (!files::isAbsolute(v))
{
auto exp = getBaseDir(v, dirs, useDefault, opts);
auto exp = getBaseDir(v, dirs, self, useDefault, opts);
if (!exp)
{
MRDOCS_TRY(v, files::makeAbsolute(v));
Expand Down Expand Up @@ -187,7 +187,8 @@ struct PublicSettingsVisitor {
Expected<std::string_view>
getBaseDir(
std::string_view referenceDirKey,
ReferenceDirectories const& dirs)
ReferenceDirectories const& dirs,
PublicSettings const& settings)
{
if (referenceDirKey == "config-dir") {
return dirs.configDir;
Expand All @@ -198,6 +199,10 @@ struct PublicSettingsVisitor {
else if (referenceDirKey == "mrdocs-root") {
return dirs.mrdocsRoot;
}
else if (referenceDirKey == "output") {
MRDOCS_ASSERT(!settings.output.empty());
return settings.output;
}
return Unexpected(formatError("unknown relative-to value: \"{}\"", referenceDirKey));
}

Expand All @@ -218,6 +223,7 @@ struct PublicSettingsVisitor {
getBaseDir(
std::string& value,
ReferenceDirectories const& dirs,
PublicSettings const& settings,
bool useDefault,
PublicSettings::OptionProperties const& opts)
{
Expand All @@ -226,7 +232,7 @@ struct PublicSettingsVisitor {
// as the base path
std::string_view relativeTo = opts.relativeto;
relativeTo = trimBaseDirReference(relativeTo);
return getBaseDir(relativeTo, dirs);
return getBaseDir(relativeTo, dirs, settings);
}

// If we used the default value, the base dir comes from
Expand All @@ -237,7 +243,7 @@ struct PublicSettingsVisitor {
referenceDirKey = referenceDirKey.substr(0, pos);
}
referenceDirKey = trimBaseDirReference(referenceDirKey);
MRDOCS_TRY(std::string_view baseDir, getBaseDir(referenceDirKey, dirs));
MRDOCS_TRY(std::string_view baseDir, getBaseDir(referenceDirKey, dirs, settings));
if (pos != std::string::npos) {
value = value.substr(pos + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion util/generate-config-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def validate_and_normalize_option(option):
option['relativeto'] = '<config-dir>'
if 'must-exist' not in option:
option['must-exist'] = True
reference_directories = ['<config-dir>', '<cwd>', '<mrdocs-root>']
reference_directories = ['<config-dir>', '<cwd>', '<mrdocs-root>', '<output>']
if option['relativeto'] not in reference_directories:
raise ValueError(f'Option "{option["name"]}" has an invalid value for "relativeto"')
default_paths = option['default']
Expand Down

0 comments on commit af97cfe

Please # to comment.