Commit 0d40c05e authored by François Grisez's avatar François Grisez

Several fixes around ConfigManager

* Remove a debug message that was printed in the standard output,
  and then could corrupt the generated configuration.
* Add missing '[module::<module_name>]' line while generating
  the configuration for one module with '--dump-default' option.
* Fix --rewrite-config
parent 773346fc
Pipeline #6245 failed with stages
in 21 minutes and 27 seconds
......@@ -658,23 +658,11 @@ class GenericManager : protected ConfigValueListener {
void sendTrap(const std::string &msg) {
mNotifier->send(&mConfigRoot, msg);
}
void applyOverrides(bool strict);
bool mNeedRestart;
bool mDirtyConfig;
void applyOverrides(bool strict) {
for (auto it = mOverrides.begin(); it != mOverrides.end(); ++it) {
const std::string &key((*it).first);
const std::string &value((*it).second);
if (value.empty())
continue;
ConfigValue *val = mConfigRoot.getDeep<ConfigValue>(key.c_str(), strict);
if (val) {
std::cout << "Overriding config with " << key << ":" << value << std::endl;
val->set(value);
} else {
std::cout << "Skipping config override " << key << ":" << value << std::endl;
}
}
}
protected:
GenericManager();
virtual ~GenericManager() {
......
......@@ -116,18 +116,15 @@ ostream &FileConfigDumper::dumpModuleHead(std::ostream &ostr, const GenericStruc
return ostr;
ostr << "##" << endl;
printHelp(ostr, moduleHead->getHelp(), "##");
ostr << "##" << endl;
if (level > 0) {
if (moduleHead->getParent()) { // if moduleHead is not the root
ostr << "[" << moduleHead->getName() << "]" << endl;
} else
ostr << endl;
ostr << endl << endl << endl;
return ostr;
}
......
......@@ -1043,6 +1043,19 @@ void GenericManager::loadStrict() {
applyOverrides(true);
}
void GenericManager::applyOverrides(bool strict) {
for (auto &it : mOverrides) {
const std::string &key = it.first;
const std::string &value = it.second;
if (value.empty()) continue;
ConfigValue *val = mConfigRoot.getDeep<ConfigValue>(key.c_str(), strict);
if (val) val->set(value);
else {
SLOGUE << "Skipping config override " << key << ":" << value;
}
}
}
GenericStruct *GenericManager::getRoot() {
return &mConfigRoot;
}
......@@ -1108,8 +1121,8 @@ int FileConfigReader::read2(GenericEntry *entry, int level) {
ConfigValue *cv;
if (cs) {
auto &entries = cs->getChildren();
for (auto it = entries.begin(); it != entries.end(); ++it) {
read2(*it, level + 1);
for (auto &entry : entries) {
read2(entry, level + 1);
}
} else if ((cv = dynamic_cast<ConfigValue *>(entry))) {
if (level < 2) {
......
......@@ -476,7 +476,9 @@ static int dump_config(su_root_t *root, const std::string &dump_cfg_part, bool w
if (pluginsDirEntry->get().empty()) {
pluginsDirEntry->set(DEFAULT_PLUGINS_DIR);
}
shared_ptr<Agent> a = make_shared<Agent>(root);
if (!dumpDefault) a->loadConfig(GenericManager::get());
GenericStruct *rootStruct = GenericManager::get()->getRoot();
if (dump_cfg_part != "all") {
......@@ -503,27 +505,25 @@ static int dump_config(su_root_t *root, const std::string &dump_cfg_part, bool w
}
}
}
ConfigDumper *dumper = NULL;
unique_ptr<ConfigDumper> dumper;
if (format == "tex") {
dumper = new TexFileConfigDumper(rootStruct);
dumper.reset(new TexFileConfigDumper(rootStruct));
} else if (format == "doku") {
dumper = new DokuwikiConfigDumper(rootStruct);
dumper.reset(new DokuwikiConfigDumper(rootStruct));
} else if (format == "file") {
FileConfigDumper *fileDumper = new FileConfigDumper(rootStruct);
fileDumper->setMode(dumpDefault ? FileConfigDumper::Mode::DefaultValue : FileConfigDumper::Mode::DefaultIfUnset);
dumper = fileDumper;
dumper.reset(fileDumper);
} else if (format == "media") {
dumper = new MediaWikiConfigDumper(rootStruct);
dumper.reset(new MediaWikiConfigDumper(rootStruct));
} else if (format == "xwiki") {
dumper = new XWikiConfigDumper(rootStruct);
dumper.reset(new XWikiConfigDumper(rootStruct));
} else {
cerr << "Invalid output format '" << format << "'" << endl;
return EXIT_FAILURE;
}
dumper->setDumpExperimentalEnabled(with_experimental);
dumper->dump(cout);
delete dumper;
return EXIT_SUCCESS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment