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

Merge patch config files

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