From c1ab9a533312d1468586caa048c608db42ed6b42 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Wed, 8 Oct 2025 07:54:04 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(rules=5Fcli):=20implement=20ad?= =?UTF-8?q?d=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add `add` subcommand to create new retention rules - allow specifying period and count for message age - support generating labels for new rules --- src/rules_cli/add_cli.rs | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/rules_cli/add_cli.rs diff --git a/src/rules_cli/add_cli.rs b/src/rules_cli/add_cli.rs new file mode 100644 index 0000000..7c135b1 --- /dev/null +++ b/src/rules_cli/add_cli.rs @@ -0,0 +1,45 @@ +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, + /// Flag to indicate that a label should be generated + #[arg(short, long)] + generate: bool, +} + +impl AddCli { + pub fn run(&self, mut config: Config) -> Result<(), Error> { + let message_age = MessageAge::new(self.period.to_string().as_str(), self.count); + let retention = Retention::new(message_age, self.generate); + config.add_rule(retention); + config.save() + } +}