From 754e5229ae3df26345545e33b192c67af82ba107 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Thu, 16 Oct 2025 17:23:50 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(cli):=20extract?= =?UTF-8?q?=20action=20execution=20into=20a=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - move action execution logic into `execute_action` function - improve code readability and reduce duplication --- src/cli/main.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index b2e38bc..7326fd9 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -136,22 +136,7 @@ async fn run_rules(client: &mut GmailClient, rules: Rules, execute: bool) -> Res }; if execute { - match action { - EolAction::Trash => { - log::info!("***executing trash messages***"); - if client.batch_trash().await.is_err() { - log::warn!("Move to trash failed for label `{label}`"); - continue; - } - } - EolAction::Delete => { - log::info!("***executing final delete messages***"); - if client.batch_delete().await.is_err() { - log::warn!("Delete failed for label `{label}`"); - continue; - } - } - } + execute_action(action, client, &label).await; } else { log::warn!("Execution stopped for dry run"); } @@ -159,3 +144,20 @@ async fn run_rules(client: &mut GmailClient, rules: Rules, execute: bool) -> Res Ok(()) } + +async fn execute_action(action: EolAction, client: &GmailClient, label: &str) { + match action { + EolAction::Trash => { + log::info!("***executing trash messages***"); + if client.batch_trash().await.is_err() { + log::warn!("Move to trash failed for label `{label}`"); + } + } + EolAction::Delete => { + log::info!("***executing final delete messages***"); + if client.batch_delete().await.is_err() { + log::warn!("Delete failed for label `{label}`"); + } + } + } +}