✨ feat(config_cli): implement action subcommand
- adds a new subcommand to configure actions on rules - allows setting action to trash or delete for a specific rule id
This commit is contained in:
committed by
Jeremiah Russell
parent
43c13dfe5f
commit
7f43b90102
35
src/config_cli/action_cli.rs
Normal file
35
src/config_cli/action_cli.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use clap::{Parser, ValueEnum};
|
||||||
|
use cull_gmail::{Config, EolAction, Error, Result};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Parser, ValueEnum)]
|
||||||
|
pub enum Action {
|
||||||
|
/// Set the action to trash
|
||||||
|
#[clap(name = "trash")]
|
||||||
|
Trash,
|
||||||
|
/// Set the action to
|
||||||
|
#[clap(name = "add")]
|
||||||
|
Delete,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
pub struct ActionCli {
|
||||||
|
/// Id of the rule on which action applies
|
||||||
|
#[clap(short, long)]
|
||||||
|
id: usize,
|
||||||
|
/// Configuration commands
|
||||||
|
#[command(subcommand)]
|
||||||
|
action: Action,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActionCli {
|
||||||
|
pub fn run(&self, mut config: Config) -> Result<()> {
|
||||||
|
if config.get_rule(self.id).is_none() {
|
||||||
|
return Err(Error::RuleNotFound(self.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.action {
|
||||||
|
Action::Trash => config.set_action_on_rule(self.id, &EolAction::Trash),
|
||||||
|
Action::Delete => config.set_action_on_rule(self.id, &EolAction::Trash),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user