Remove unknown params from config file

This commit is contained in:
Rafael Moraes
2025-10-27 15:06:24 -03:00
parent fdab6481ea
commit 4cfb626d00
2 changed files with 16 additions and 0 deletions
+15
View File
@@ -92,6 +92,21 @@ class ConfigFile:
if has_changes:
self._write_config_file()
def cleanup_unknown_params(
self,
params: list[click.Parameter],
) -> None:
param_names = {param.name for param in params}
has_changes = False
for key in list(self.config[self.section_name].keys()):
if key not in param_names:
self.config.remove_option(self.section_name, key)
has_changes = True
if has_changes:
self._write_config_file()
def parse_params_from_config(
self,
params: list[click.Parameter],
+1
View File
@@ -118,6 +118,7 @@ def load_config_file(
return ctx
config_file = ConfigFile(ctx.params["config_path"])
config_file.cleanup_unknown_params(ctx.command.params)
config_file.add_params_default_to_config(
ctx.command.params,
)