♻️ refactor(cli): move rm_cli to new directory
- move the rm_cli module from src/config_cli/rules_cli/ to src/cli/config_cli/rules_cli/
This commit is contained in:
committed by
Jeremiah Russell
parent
7d55e6bbd4
commit
801628310b
32
src/cli/config_cli/rules_cli/rm_cli.rs
Normal file
32
src/cli/config_cli/rules_cli/rm_cli.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use clap::Parser;
|
||||
use cull_gmail::{Config, Error};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
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 {
|
||||
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)?;
|
||||
config.save()?;
|
||||
}
|
||||
|
||||
if let Some(label) = &self.label {
|
||||
config.remove_rule_by_label(label)?;
|
||||
config.save()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user