Add a special "root" value for [options]

This commit is contained in:
Duncan Ogilvie
2023-02-28 19:34:31 +01:00
parent a499df84b1
commit b869e5646f
4 changed files with 37 additions and 5 deletions
+25 -2
View File
@@ -377,10 +377,33 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
const auto &value = itr.second;
if (value.is_boolean()) {
o.value = value.as_boolean();
} else {
} else if (value.is_string()) {
auto str = std::string(value.as_string());
if (str == "root") {
o.value = std::string("${CMKR_ROOT_PROJECT}");
} else {
throw_key_error("Unsupported option value '" + str + "'", str, value);
}
} else if (value.is_table()) {
auto &option = checker.create(value);
option.optional("help", o.help);
option.optional("value", o.value);
if (option.contains("value")) {
const auto &ovalue = option.find("value");
if (ovalue.is_boolean()) {
o.value = ovalue.as_boolean();
} else if (ovalue.is_string()) {
auto str = std::string(ovalue.as_string());
if (str == "root") {
o.value = std::string("${CMKR_ROOT_PROJECT}");
} else {
throw_key_error("Unsupported option value '" + str + "'", str, value);
}
} else {
throw_key_error(toml::concat_to_string("Unsupported value type: ", ovalue.type()), "value", value);
}
}
} else {
throw_key_error(toml::concat_to_string("Unsupported value type: ", itr.second.type()), itr.first, itr.second);
}
options.push_back(o);
conditions.emplace(o.name, o.name);