Skip to content
Snippets Groups Projects
Commit 1011818f authored by Nicolas Pope's avatar Nicolas Pope
Browse files

WIP config change

parent a78220c5
Branches
Tags
No related merge requests found
......@@ -103,12 +103,18 @@ T *ftl::config::create(json_t &link, ARGS ...args) {
template <typename T, typename... ARGS>
T *ftl::config::create(ftl::Configurable *parent, const std::string &name, ARGS ...args) {
nlohmann::json &entity = ftl::config::resolve(parent->getConfig()[name]);
//nlohmann::json &entity = ftl::config::resolve(parent->getConfig()[name]);
nlohmann::json &entity = (parent->getConfig()[name].is_structured()) ? parent->getConfig()[name] : ftl::config::resolve(parent->getConfig())[name];
if (entity.is_object()) {
if (!entity["$id"].is_string()) {
// TODO(Nick) Check for # in URI
entity["$id"] = *parent->get<std::string>("$id") + std::string("/") + name;
std::string id_str = *parent->get<std::string>("$id");
if (id_str.find('#') != std::string::npos) {
entity["$id"] = id_str + std::string("/") + name;
} else {
entity["$id"] = id_str + std::string("#") + name;
}
}
} /*else {
nlohmann::json &res = resolve(entity);
......
......@@ -192,7 +192,12 @@ json_t &ftl::config::resolve(const std::string &puri) {
// TODO(Nick) Must support alternative root (last $id)
if (uri_str.at(0) == '#') {
uri_str = config["$id"].get<string>() + uri_str;
string id_str = config["$id"].get<string>();
if (id_str.find('#') != string::npos) {
uri_str[0] = '/';
} // else {
uri_str = id_str + uri_str;
//}
}
ftl::URI uri(uri_str);
......@@ -355,15 +360,18 @@ static void process_options(Configurable *root, const map<string, string> &opts)
}
try {
auto ptr = nlohmann::json::json_pointer("/"+opt.first);
// TODO(nick) Allow strings without quotes
//auto ptr = nlohmann::json::json_pointer("/"+opt.first);
auto ptr = ftl::config::resolve(*root->get<string>("$id") + string("/") + opt.first);
LOG(INFO) << "PARAM RES TO " << (*root->get<string>("$id") + string("/") + opt.first);
auto v = nlohmann::json::parse(opt.second);
std::string type = root->getConfig().at(ptr).type_name();
std::string type = ptr.type_name();
if (type != "null" && v.type_name() != type) {
LOG(ERROR) << "Incorrect type for argument " << opt.first << " - expected '" << type << "', got '" << v.type_name() << "'";
continue;
}
root->getConfig().at(ptr) = v;
ptr.update(v);
} catch(...) {
LOG(ERROR) << "Unrecognised option: " << *root->get<string>("$id") << "#" << opt.first;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment