Add default handling and write functionality to `ConfigManager`
- Ensure missing or empty config values are replaced with defaults. - Write updated configuration back to `config.toml` using `tomli_w`.
This commit is contained in:
parent
e8d5159973
commit
59178d3cec
|
|
@ -54,3 +54,13 @@ class ConfigManager(metaclass=SingletonMeta):
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for key, default_value in default.items():
|
||||||
|
current_value = self.__data.get(key)
|
||||||
|
if current_value is None or current_value == "":
|
||||||
|
self.__data[key] = default_value
|
||||||
|
else:
|
||||||
|
self.__data[key] = current_value
|
||||||
|
with open(f"{self.config_dir}/config.toml", "wb") as f:
|
||||||
|
tomli_w.dump(self.__data, f)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue