feat(cli): add remove label subcommand

- add `remove-label` subcommand to remove labels from rules
This commit is contained in:
Jeremiah Russell
2025-10-09 14:40:35 +01:00
committed by Jeremiah Russell
parent 278171503f
commit 7d55e6bbd4
2 changed files with 23 additions and 50 deletions

View File

@@ -0,0 +1,23 @@
use clap::Parser;
use cull_gmail::{Config, Error, Result};
#[derive(Debug, Parser)]
pub struct RemoveCli {
/// Id of the rule on which action applies
#[clap(short, long)]
id: usize,
/// Label to remove from the rule
#[clap(short, long)]
label: String,
}
impl RemoveCli {
pub fn run(&self, mut config: Config) -> Result<()> {
if config.get_rule(self.id).is_none() {
return Err(Error::RuleNotFound(self.id));
}
config.remove_label_from_rule(self.id, &self.label)
}
}

View File

@@ -1,50 +0,0 @@
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<String>,
/// 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()
}
}