♻️ refactor(cli): extract action execution into a function
- move action execution logic into `execute_action` function - improve code readability and reduce duplication
This commit is contained in:
committed by
Jeremiah Russell
parent
9116e7c406
commit
754e5229ae
@@ -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}`");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user