cull-gmail 0.1.8

Cull emails from a gmail account using the gmail API
Documentation
use clap::Parser;
use cull_gmail::{Error, Rules};

#[derive(Debug, Parser)]
pub struct RmRuleCli {
    /// Id of the rule to remove
    #[clap(short, long)]
    id: Option<usize>,
    /// Label in the rule to remove (the rule will be removed)
    #[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(())
    }
}