✨ feat(cli): implement rule execution logic
- add logic to iterate through labels and execute associated rules - retrieve rules based on label and perform actions like trashing/deleting messages - log warnings for missing rules or invalid actions
This commit is contained in:
committed by
Jeremiah Russell
parent
6a7c67cffc
commit
fb7154f752
@@ -1,11 +1,32 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cull_gmail::Result;
|
use cull_gmail::{Config, EolAction, Result};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct RunCli {}
|
pub struct RunCli {}
|
||||||
|
|
||||||
impl RunCli {
|
impl RunCli {
|
||||||
pub async fn run(&self, _credential: &str) -> Result<()> {
|
pub async fn run(&self, config: Config) -> Result<()> {
|
||||||
|
let rules = config.get_rules_by_label();
|
||||||
|
|
||||||
|
for label in config.labels() {
|
||||||
|
let Some(rule) = rules.get(&label) else {
|
||||||
|
log::warn!("no rule found for label `{label}`");
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
log::info!("Executing rule `#{}` for label `{label}`", rule.describe());
|
||||||
|
|
||||||
|
let Some(action) = rule.action() else {
|
||||||
|
log::warn!("no valid action specified for rule #{}", rule.id());
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
match action {
|
||||||
|
EolAction::Trash => log::info!("trashing older messages"),
|
||||||
|
EolAction::Delete => log::info!("deleting older messages"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user