feat(config): add remove label from rule

- implement remove_label_from_rule function to delete labels from rules
- add error handling for rule not found
- save configuration after removing the label
This commit is contained in:
Jeremiah Russell
2025-10-09 12:24:12 +01:00
committed by Jeremiah Russell
parent eaa7d4be12
commit 66dd0dc983

View File

@@ -161,6 +161,18 @@ impl Config {
Ok(()) Ok(())
} }
/// Remove a label from the rule identified by the id
pub fn remove_label_from_rule(&mut self, id: usize, label: &str) -> Result<()> {
let Some(rule) = self.rules.get_mut(id.to_string().as_str()) else {
return Err(Error::RuleNotFound(id));
};
rule.remove_label(label);
self.save()?;
println!("Label `{label}` removed from rule `#{id}`");
Ok(())
}
/// Save the current configuration to the file /// Save the current configuration to the file
pub fn save(&self) -> Result<()> { pub fn save(&self) -> Result<()> {
let home_dir = env::home_dir().unwrap(); let home_dir = env::home_dir().unwrap();