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

Merge patch config files

parent f6adcb24
No related branches found
No related tags found
No related merge requests found
......@@ -94,26 +94,49 @@ optional<string> locateFile(const string &name, const vector<string> &paths) {
return {};
}
/**
* Combine one json config with another patch json config.
*/
static bool mergeConfig(const string &path) {
ifstream i;
i.open(path);
if (i.is_open()) {
json t;
i >> t;
config.merge_patch(t);
return true;
} else {
return false;
}
}
/**
* Find and load a JSON configuration file
*/
static bool findConfiguration(const string &file, const vector<string> &paths,
const std::string &app) {
ifstream i;
bool found = false;
if (file != "") i.open(file);
if (!i.is_open()) {
auto f = locateFile("config.json", paths);
if (!f) return false;
i.open(*f);
}
found |= mergeConfig(FTL_GLOBAL_CONFIG_ROOT "/config.json");
found |= mergeConfig(FTL_LOCAL_CONFIG_ROOT "/config.json");
found |= mergeConfig("./config.json");
if (!i.is_open()) return false;
for (auto p : paths) {
if (is_directory(p)) {
found |= mergeConfig(p+"/config.json");
}
}
i >> config;
config = config[app];
return true;
if (file != "") {
found |= mergeConfig(file);
}
if (found) {
config = config[app];
return true;
} else {
return false;
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment