Skip to content

Commit

Permalink
fix the default value logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Taepper committed Nov 21, 2024
1 parent fa6e956 commit ad79d7a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/config/config_specification.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace silo::config {
/// be supported by env vars or config files anyway, although could
/// still be specified for command line, but that's not implemented
/// currently.
class ConfigSpecification : public VerifiedConfigSource {
class ConfigSpecification {
public:
/// The name of the program for which this config is used. This will be printed in the help text
std::string_view program_name;
Expand All @@ -35,6 +35,8 @@ class ConfigSpecification : public VerifiedConfigSource {
std::optional<ConfigValueSpecification> getValueSpecificationFromAmbiguousKey(
const AmbiguousConfigKeyPath& key
) const;

VerifiedConfigSource getConfigSourceFromDefaults() const;
};

} // namespace silo::config
11 changes: 11 additions & 0 deletions src/config/config_specification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,15 @@ std::string ConfigSpecification::helpText() const {

return help_text.str();
}

VerifiedConfigSource ConfigSpecification::getConfigSourceFromDefaults() const {
VerifiedConfigSource result;
for (auto& x : fields) {
if (x.default_value) {
result.config_values.emplace(x.key, x.default_value.value());
}
}
return result;
}

} // namespace silo::config
2 changes: 1 addition & 1 deletion src/silo/config/preprocessing_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ConfigSpecification PreprocessingConfig::getConfigSpecification() {
}

PreprocessingConfig::PreprocessingConfig() {
overwriteFrom(getConfigSpecification());
overwriteFrom(getConfigSpecification().getConfigSourceFromDefaults());
}

void PreprocessingConfig::validate() const {
Expand Down
2 changes: 1 addition & 1 deletion src/silo/config/runtime_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ConfigSpecification RuntimeConfig::getConfigSpecification() {
}

RuntimeConfig::RuntimeConfig() {
overwriteFrom(getConfigSpecification());
overwriteFrom(getConfigSpecification().getConfigSourceFromDefaults());
}

bool RuntimeConfig::asksForHelp() const {
Expand Down

0 comments on commit ad79d7a

Please sign in to comment.