From 2110d563314c7c4722beafa78cb47de129a07555 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Sat, 11 Oct 2025 09:30:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(cli):=20extract?= =?UTF-8?q?=20action=20execution=20to=20separate=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - move action execution logic into its own function - improve readability and maintainability --- src/cli/run_cli.rs | 60 ++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/cli/run_cli.rs b/src/cli/run_cli.rs index c7771bc..2105301 100644 --- a/src/cli/run_cli.rs +++ b/src/cli/run_cli.rs @@ -30,36 +30,40 @@ impl RunCli { continue; }; - match action { - EolAction::Trash => { - if !self.skip_trash { - log::info!("trashing older messages"); - match processor.trash_messages(&label).await { - Ok(_) => {} - 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 => { - if !self.skip_delete { - log::info!("deleting older messages"); - match processor.delete_messages(&label).await { - Ok(_) => {} - Err(e) => { - log::warn!("action failed for label {label} with error {e}"); - } - } - } else { - log::warn!("Rule with `delete` action for label `{label}` skipped."); - } - } - } + self.execute_action(processor, action, &label).await; } Ok(()) } + + async fn execute_action<'a>(&self, processor: Processor<'a>, action: EolAction, label: &str) { + match action { + EolAction::Trash => { + if !self.skip_trash { + log::info!("trashing older messages"); + match processor.trash_messages(label).await { + Ok(_) => {} + 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 => { + if !self.skip_delete { + log::info!("deleting older messages"); + match processor.delete_messages(label).await { + Ok(_) => {} + Err(e) => { + log::warn!("action failed for label {label} with error {e}"); + } + } + } else { + log::warn!("Rule with `delete` action for label `{label}` skipped."); + } + } + } + } }