From fdc36096dc579caffbfd6f13345285d7b91ef966 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Thu, 9 Oct 2025 14:02:25 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(config):=20add=20functionality?= =?UTF-8?q?=20to=20set=20action=20on=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add `set_action_on_rule` function to modify rule action - allow users to update action (e.g., delete) for specific rules --- src/config.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 929c5be..0ed803e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,7 +11,7 @@ mod eol_rule; use eol_rule::EolRule; -use crate::{Error, MessageAge, Result, Retention, eol_cmd::EolAction}; +use crate::{EolAction, Error, MessageAge, Result, Retention}; /// Configuration file for the program #[derive(Debug, Serialize, Deserialize)] @@ -85,7 +85,7 @@ impl Config { rule.add_label(l); } if delete { - rule.set_command(EolAction::Delete); + rule.set_command(&EolAction::Delete); } log::info!("added rule: {rule}"); self.rules.insert(rule.id().to_string(), rule); @@ -173,6 +173,18 @@ impl Config { Ok(()) } + /// Set the action on the rule identified by the id + pub fn set_action_on_rule(&mut self, id: usize, action: &EolAction) -> Result<()> { + let Some(rule) = self.rules.get_mut(id.to_string().as_str()) else { + return Err(Error::RuleNotFound(id)); + }; + rule.set_command(action); + self.save()?; + println!("Action set to `{action}` on rule `#{id}`"); + + Ok(()) + } + /// Save the current configuration to the file pub fn save(&self) -> Result<()> { let home_dir = env::home_dir().unwrap();