Consolidate Configuration generate INI functions

pull/1186/head
Stephen Shelton 4 years ago
parent 1b19314278
commit d9340a873e
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -62,7 +62,7 @@ Configuration::validate()
}
std::string
Configuration::generateDefaultConfig()
Configuration::generateINIConfig(bool useValues)
{
std::ostringstream oss;
@ -75,7 +75,16 @@ Configuration::generateDefaultConfig()
oss << "[" << section << "]\n";
visitDefinitions(section, [&](const std::string& name, const ConfigDefinition_ptr& def) {
oss << name << "=" << def->defaultValueAsString() << "\n";
if (useValues and def->numFound > 0)
{
oss << name << "=" << def->writeValue(false) << "\n";
}
else
{
if (not def->required)
oss << "# ";
oss << name << "=" << def->defaultValueAsString() << "\n";
}
});
sectionsVisited++;
@ -84,12 +93,6 @@ Configuration::generateDefaultConfig()
return oss.str();
}
std::string
Configuration::generateOverridenConfig()
{
return "Implement me!";
}
const ConfigDefinition_ptr&
Configuration::lookupDefinitionOrThrow(string_view section, string_view name) const
{

@ -164,11 +164,19 @@ namespace llarp
void
validate();
/// Generate a config string from the current config definition, optionally using overridden
/// values. The generated config will preserve insertion order of both sections and their
/// definitions.
///
/// Definitions which are required or have an overriden value (and useValues == true) will be
/// written normally. Otherwise, they will be written commented-out in order to provide a
/// complete documentation of the configuration file.
///
/// @param useValues specifies whether we use specified values (e.g. those from calls to
/// addConfigValue()) or only definitions
/// @return a string containing the config in INI format
std::string
generateDefaultConfig();
std::string
generateOverridenConfig();
generateINIConfig(bool useValues = false);
private:

Loading…
Cancel
Save