Add properties files to loadConfig

This commit is contained in:
Mike Bierlee 2022-10-09 00:12:24 +03:00
parent 4c9f007be7
commit 4ee94f8a9c
2 changed files with 13 additions and 1 deletions

View file

@ -20,6 +20,7 @@ import std.process : environment;
import std.typecons : Flag; import std.typecons : Flag;
import mirage.json : loadJsonConfig; import mirage.json : loadJsonConfig;
import mirage.java : loadJavaProperties;
/** /**
* Used by the ConfigDictionary when something goes wrong when reading configuration. * Used by the ConfigDictionary when something goes wrong when reading configuration.
@ -598,6 +599,10 @@ ConfigDictionary loadConfig(const string configPath) {
return loadJsonConfig(configPath); return loadJsonConfig(configPath);
} }
if (extension == ".properties") {
return loadJavaProperties(configPath);
}
throw new ConfigCreationException( throw new ConfigCreationException(
"File extension '" ~ extension ~ "' is not recognized as a supported config file format. Please use a specific function to load it, such as 'loadJsonConfig()'"); "File extension '" ~ extension ~ "' is not recognized as a supported config file format. Please use a specific function to load it, such as 'loadJsonConfig()'");
} }
@ -839,11 +844,15 @@ version (unittest) {
@("Load configurations using the loadConfig convenience function") @("Load configurations using the loadConfig convenience function")
unittest { unittest {
auto jsonConfig = loadConfig("testfiles/groot.json"); auto jsonConfig = loadConfig("testfiles/groot.json");
assert(jsonConfig.get("name") == "Groot"); assert(jsonConfig.get("name") == "Groot");
assert(jsonConfig.get("traits[1]") == "tree"); assert(jsonConfig.get("traits[1]") == "tree");
assert(jsonConfig.get("age") == "8728"); assert(jsonConfig.get("age") == "8728");
assert(jsonConfig.get("taxNumber") == null); assert(jsonConfig.get("taxNumber") == null);
auto javaProperties = loadConfig("testfiles/groot.properties");
assert(javaProperties.get("name") == "Groot");
assert(javaProperties.get("age") == "8728");
assert(javaProperties.get("taxNumber") == "null");
} }
@("Whitespace is preserved in values") @("Whitespace is preserved in values")

View file

@ -0,0 +1,3 @@
name=Groot
age=8728
taxNumber=null