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(()) } }