feat(cli): add option to skip trash actions

- introduce `--skip-trash` flag to prevent trashing messages
- add warning log when a trash action is skipped due to the flag
This commit is contained in:
Jeremiah Russell
2025-10-11 07:37:15 +01:00
committed by Jeremiah Russell
parent 81157e6ce9
commit 1997fd2142

View File

@@ -2,7 +2,11 @@ use clap::Parser;
use cull_gmail::{Config, EolAction, Processor, Result}; use cull_gmail::{Config, EolAction, Processor, Result};
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
pub struct RunCli {} pub struct RunCli {
/// Skip any rules that apply the action `trash`
#[clap(short = 't', long)]
skip_trash: bool,
}
impl RunCli { impl RunCli {
pub async fn run(&self, config: Config) -> Result<()> { pub async fn run(&self, config: Config) -> Result<()> {
@@ -25,12 +29,16 @@ impl RunCli {
match action { match action {
EolAction::Trash => { EolAction::Trash => {
log::info!("trashing older messages"); if !self.skip_trash {
match processor.trash_messages(&label).await { log::info!("trashing older messages");
Ok(_) => {} match processor.trash_messages(&label).await {
Err(e) => { Ok(_) => {}
log::warn!("action failed for label {label} with error {e}"); Err(e) => {
log::warn!("action failed for label {label} with error {e}");
}
} }
} else {
log::warn!("Rule with `trash` action for label `{label}` skipped.");
} }
} }
EolAction::Delete => { EolAction::Delete => {