✨ feat(rules_cli): implement rule removal
- add `rm` subcommand to remove rules by id or label - add `id` and `label` options to `rm` subcommand - implement `remove_rule_by_id` and `remove_rule_by_label` in `Config`
This commit is contained in:
committed by
Jeremiah Russell
parent
6df0ef6536
commit
16145f8b22
@@ -2,10 +2,29 @@ use clap::Parser;
|
|||||||
use cull_gmail::{Config, Error};
|
use cull_gmail::{Config, Error};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct RmCli {}
|
pub struct RmCli {
|
||||||
|
/// 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 RmCli {
|
impl RmCli {
|
||||||
pub fn run(&self, _config: Config) -> Result<(), Error> {
|
pub fn run(&self, mut config: Config) -> 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)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(label) = &self.label {
|
||||||
|
config.remove_rule_by_label(label)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user