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