✨ 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:
committed by
Jeremiah Russell
parent
b8a473c978
commit
0c8da9aa23
23
src/cli/config_cli/label_cli/add_cli.rs
Normal file
23
src/cli/config_cli/label_cli/add_cli.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user