Changed NymConfig to take optional id for some of its method

This commit is contained in:
Jedrzej Stuczynski
2020-01-30 16:09:53 +00:00
parent 2e63f95b76
commit 51e43547ed
+10 -6
View File
@@ -12,12 +12,16 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned {
fn default_root_directory() -> PathBuf;
// default, most probable, implementations; can be easily overridden where required
fn default_config_directory() -> PathBuf {
Self::default_root_directory().join("config")
fn default_config_directory(id: Option<&str>) -> PathBuf {
Self::default_root_directory()
.join(id.unwrap_or(""))
.join("config")
}
fn default_data_directory() -> PathBuf {
Self::default_root_directory().join("data")
fn default_data_directory(id: Option<&str>) -> PathBuf {
Self::default_root_directory()
.join(id.unwrap_or(""))
.join("data")
}
fn root_directory(&self) -> PathBuf;
@@ -35,9 +39,9 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned {
)
}
fn load_from_file(custom_location: Option<PathBuf>) -> io::Result<Self> {
fn load_from_file(custom_location: Option<PathBuf>, id: Option<&str>) -> io::Result<Self> {
let config_contents = fs::read_to_string(
custom_location.unwrap_or(Self::default_config_directory().join("config.toml")),
custom_location.unwrap_or(Self::default_config_directory(id).join("config.toml")),
)?;
let parsing_result = toml::from_str(&config_contents)