♻️ refactor(cli): rename action_cli module
- move action_cli module to follow project structure
This commit is contained in:
committed by
Jeremiah Russell
parent
d4de088fd4
commit
752f0f8c34
35
src/cli/config_cli/action_cli.rs
Normal file
35
src/cli/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