From 7f43b901029d13d619aaa6e1c75aaeafe09ba6db Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Thu, 9 Oct 2025 14:01:49 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(config=5Fcli):=20implement=20a?= =?UTF-8?q?ction=20subcommand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - adds a new subcommand to configure actions on rules - allows setting action to trash or delete for a specific rule id --- src/config_cli/action_cli.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/config_cli/action_cli.rs diff --git a/src/config_cli/action_cli.rs b/src/config_cli/action_cli.rs new file mode 100644 index 0000000..b9da63a --- /dev/null +++ b/src/config_cli/action_cli.rs @@ -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), + } + } +}