Factor out config string list reading into a separate function

This commit is contained in:
Daniel Schulte 2020-12-01 22:56:48 +01:00
parent 0f777ef139
commit 6081b9e542
1 changed files with 14 additions and 9 deletions

View File

@ -474,6 +474,19 @@ static std::string get_module_path() {
return std::string(exe); return std::string(exe);
} }
void config_get_string_list(std::vector<std::string> &buffer, const json &obj, const std::string &key) {
if(!obj.contains(key) || !obj[key].is_array())
return;
buffer.clear();
for(const json &elem: obj[key]) {
if(!elem.is_string()) {
tui_abort("Configuration error: " + key + " element " + elem.dump() + " is not a string but " + elem.type_name() + ".");
}
buffer.push_back(elem);
}
}
int main() int main()
{ {
const std::string module_path = get_module_path(); const std::string module_path = get_module_path();
@ -509,15 +522,7 @@ int main()
if(config.count("database") && config["database"].is_string()) { if(config.count("database") && config["database"].is_string()) {
database_filename = replace(config["database"], "$HOME", user_home); database_filename = replace(config["database"], "$HOME", user_home);
} }
if(config.count("watchCommand") && config["watchCommand"].is_array()) { config_get_string_list(watch_command, config, "watchCommand");
watch_command.clear();
for(const json &elem: config["watchCommand"]) {
if(!elem.is_string()) {
tui_abort("Configuration error: watchCommand element " + elem.dump() + " is not a string but " + elem.type_name() + ".");
}
watch_command.push_back(elem);
}
}
db_init(database_filename); db_init(database_filename);
make_virtual_unwatched_channel(); make_virtual_unwatched_channel();