feat(cli): add list labels subcommand

- add `list` subcommand to `label` subcommand to list labels in rule
- remove `remove` subcommand from `label` subcommand
This commit is contained in:
Jeremiah Russell
2025-10-09 14:40:27 +01:00
committed by Jeremiah Russell
parent 0c8da9aa23
commit 278171503f
2 changed files with 29 additions and 23 deletions

View File

@@ -0,0 +1,29 @@
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(())
}
}

View File

@@ -1,23 +0,0 @@
use clap::Parser;
use cull_gmail::{Config, Error, Result};
#[derive(Debug, Parser)]
pub struct RemoveCli {
/// Id of the rule on which action applies
#[clap(short, long)]
id: usize,
/// Label to remove from the rule
#[clap(short, long)]
label: String,
}
impl RemoveCli {
pub fn run(&self, mut config: Config) -> Result<()> {
if config.get_rule(self.id).is_none() {
return Err(Error::RuleNotFound(self.id));
}
config.remove_label_from_rule(self.id, &self.label)
}
}