use clap::Parser;
use cull_gmail::{Error, Rules};
#[derive(Debug, Parser)]
pub struct RmRuleCli {
#[clap(short, long)]
id: Option<usize>,
#[clap(short, long)]
label: Option<String>,
}
impl RmRuleCli {
pub fn run(&self, mut config: Rules) -> Result<(), Error> {
if self.id.is_none() && self.label.is_none() {
return Err(Error::NoRuleSelector);
}
if let Some(id) = self.id {
config.remove_rule_by_id(id)?;
config.save()?;
}
if let Some(label) = &self.label {
config.remove_rule_by_label(label)?;
config.save()?;
}
Ok(())
}
}