feat(label): implement add label command

- adds a new subcommand to add labels to existing rules
- removes list label subcommand
This commit is contained in:
Jeremiah Russell
2025-10-09 14:40:18 +01:00
committed by Jeremiah Russell
parent b8a473c978
commit 0c8da9aa23
2 changed files with 23 additions and 29 deletions

View File

@@ -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)
}
}

View File

@@ -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(())
}
}