From 16145f8b2270eb294e512af84eb9fa5b561ab38d Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Wed, 8 Oct 2025 16:15:08 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(rules=5Fcli):=20implement=20ru?= =?UTF-8?q?le=20removal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add `rm` subcommand to remove rules by id or label - add `id` and `label` options to `rm` subcommand - implement `remove_rule_by_id` and `remove_rule_by_label` in `Config` --- src/rules_cli/rm_cli.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/rules_cli/rm_cli.rs b/src/rules_cli/rm_cli.rs index aac19fe..4b276a6 100644 --- a/src/rules_cli/rm_cli.rs +++ b/src/rules_cli/rm_cli.rs @@ -2,10 +2,29 @@ use clap::Parser; use cull_gmail::{Config, Error}; #[derive(Debug, Parser)] -pub struct RmCli {} +pub struct RmCli { + /// Id of the rule to remove + #[clap(short, long)] + id: Option, + /// Label in the rule to remove (the rule will be removed) + #[clap(short, long)] + label: Option, +} impl RmCli { - pub fn run(&self, _config: Config) -> Result<(), Error> { + pub fn run(&self, mut config: Config) -> Result<(), Error> { + if self.id.is_none() && self.label.is_none() { + return Err(Error::NoRuleSelector); + } + + if let Some(id) = self.id { + config.remove_rule_by_id(id)?; + } + + if let Some(label) = &self.label { + config.remove_rule_by_label(label)?; + } + Ok(()) } }