From 0c8da9aa236cf3d70b6c941750e2c1a255117e02 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Thu, 9 Oct 2025 14:40:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(label):=20implement=20add=20la?= =?UTF-8?q?bel=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - adds a new subcommand to add labels to existing rules - removes list label subcommand --- src/cli/config_cli/label_cli/add_cli.rs | 23 ++++++++++++++++++++ src/config_cli/label_cli/list_cli.rs | 29 ------------------------- 2 files changed, 23 insertions(+), 29 deletions(-) create mode 100644 src/cli/config_cli/label_cli/add_cli.rs delete mode 100644 src/config_cli/label_cli/list_cli.rs diff --git a/src/cli/config_cli/label_cli/add_cli.rs b/src/cli/config_cli/label_cli/add_cli.rs new file mode 100644 index 0000000..ac74eb9 --- /dev/null +++ b/src/cli/config_cli/label_cli/add_cli.rs @@ -0,0 +1,23 @@ +use clap::Parser; + +use cull_gmail::{Config, Error, Result}; + +#[derive(Debug, Parser)] +pub struct AddCli { + /// Id of the rule on which action applies + #[clap(short, long)] + id: usize, + /// Label to add to the rule + #[clap(short, long)] + label: String, +} + +impl AddCli { + pub fn run(&self, mut config: Config) -> Result<()> { + if config.get_rule(self.id).is_none() { + return Err(Error::RuleNotFound(self.id)); + } + + config.add_label_to_rule(self.id, &self.label) + } +} diff --git a/src/config_cli/label_cli/list_cli.rs b/src/config_cli/label_cli/list_cli.rs deleted file mode 100644 index b6debb3..0000000 --- a/src/config_cli/label_cli/list_cli.rs +++ /dev/null @@ -1,29 +0,0 @@ -use clap::Parser; - -use cull_gmail::{Config, Error, Result}; - -#[derive(Debug, Parser)] -pub struct ListCli { - /// Id of the rule on which action applies - #[clap(short, long)] - id: usize, -} - -impl ListCli { - pub fn run(&self, config: Config) -> Result<()> { - let Some(rule) = config.get_rule(self.id) else { - return Err(Error::RuleNotFound(self.id)); - }; - - print!("Labels in rule: "); - for (i, label) in rule.labels().iter().enumerate() { - if i != 0 { - print!(", {label}"); - } else { - print!("`{label}"); - } - } - println!("`"); - Ok(()) - } -}