From 44d8eef87253acba8dd25a553ad917e16a422c80 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Thu, 9 Oct 2025 14:40:58 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(rules=5Fcli):=20implement=20ad?= =?UTF-8?q?d=20command=20for=20managing=20retention=20rules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add `add` subcommand to manage retention rules - introduce `Period` enum for specifying time units - implement logic to add and save new retention rules to the configuration --- src/cli/config_cli/rules_cli/add_cli.rs | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/cli/config_cli/rules_cli/add_cli.rs diff --git a/src/cli/config_cli/rules_cli/add_cli.rs b/src/cli/config_cli/rules_cli/add_cli.rs new file mode 100644 index 0000000..8f56969 --- /dev/null +++ b/src/cli/config_cli/rules_cli/add_cli.rs @@ -0,0 +1,50 @@ +use std::fmt; + +use clap::{Parser, ValueEnum}; +use cull_gmail::{Config, Error, MessageAge, Retention}; + +#[derive(Debug, Clone, Parser, ValueEnum)] +pub enum Period { + Days, + Weeks, + Months, + Years, +} + +impl fmt::Display for Period { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Period::Days => write!(f, "days"), + Period::Weeks => write!(f, "weeks"), + Period::Months => write!(f, "months"), + Period::Years => write!(f, "years"), + } + } +} + +#[derive(Debug, Parser)] +pub struct AddCli { + /// Period for the rule + #[arg(short, long)] + period: Period, + /// Count of the period + #[arg(short, long, default_value = "1")] + count: usize, + /// Optional specific label; if not specified one will be generated + #[arg(short, long)] + label: Option, + /// Immediate delete instead of move to trash + #[arg(long)] + delete: bool, +} + +impl AddCli { + pub fn run(&self, mut config: Config) -> Result<(), Error> { + let generate = self.label.is_none(); + let message_age = MessageAge::new(self.period.to_string().as_str(), self.count); + let retention = Retention::new(message_age, generate); + + config.add_rule(retention, self.label.as_ref(), self.delete); + config.save() + } +}