✨ feat(cli): restructure rules config CLI
- 【Refactor】Move label subcommands (add, list, remove) into separate modules for better organization - 【Refactor】Rename `LabelCli` to `ListLabelCli`, `AddCli` to `AddLabelCli`, and `RemoveCli` to `RemoveLabelCli` - 【Refactor】Rename `LabelCommands` to `List`, `Add`, and `Remove` - 【Refactor】Rename `remove-rule` alias to `rm-rule` and `remove-label` alias to `rm-label` - 【Feat】Add `ListLabelCli`, `AddLabelCli`, and `RemoveLabelCli` to handle label-related operations - 【Feat】Update `ConfigCli` to use the new label subcommands and modules - 【Remove】Remove the `label_cli.rs` file as its functionality is now distributed
This commit is contained in:
committed by
Jeremiah Russell
parent
9773327e86
commit
209b8a6a46
@@ -1,31 +1,40 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
mod action_rule_cli;
|
mod action_rule_cli;
|
||||||
|
mod add_label_cli;
|
||||||
mod add_rule_cli;
|
mod add_rule_cli;
|
||||||
mod label_cli;
|
mod list_label_cli;
|
||||||
|
mod remove_label_cli;
|
||||||
mod rm_rule_cli;
|
mod rm_rule_cli;
|
||||||
|
|
||||||
use action_rule_cli::ActionRuleCli;
|
use action_rule_cli::ActionRuleCli;
|
||||||
|
use add_label_cli::AddLabelCli;
|
||||||
use cull_gmail::{Result, Rules};
|
use cull_gmail::{Result, Rules};
|
||||||
use label_cli::LabelCli;
|
use list_label_cli::ListLabelCli;
|
||||||
|
use remove_label_cli::RemoveLabelCli;
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum SubCmds {
|
enum SubCmds {
|
||||||
/// List the rules configured and saved in the config file
|
/// List the rules configured and saved in the config file
|
||||||
#[clap(name = "list")]
|
#[clap(name = "list-rules")]
|
||||||
List,
|
ListRules,
|
||||||
/// Add a rules to the config file
|
/// Add a rules to the config file
|
||||||
#[clap(name = "add-rule")]
|
#[clap(name = "add-rule")]
|
||||||
Add(add_rule_cli::AddRuleCli),
|
AddRule(add_rule_cli::AddRuleCli),
|
||||||
/// Remove a rule from the config file
|
/// Remove a rule from the config file
|
||||||
#[clap(name = "remove-rule", alias = "rm")]
|
#[clap(name = "remove-rule", alias = "rm-rule")]
|
||||||
Remove(rm_rule_cli::RmRuleCli),
|
RemoveRule(rm_rule_cli::RmRuleCli),
|
||||||
/// Add or remove Label from rule
|
|
||||||
#[clap(name = "label")]
|
|
||||||
Label(LabelCli),
|
|
||||||
/// Set action on a specific rule
|
|
||||||
#[clap(name = "set-action-on-rule")]
|
#[clap(name = "set-action-on-rule")]
|
||||||
Action(ActionRuleCli),
|
ActionRule(ActionRuleCli),
|
||||||
|
/// List the labels associated with a rule
|
||||||
|
#[clap(name = "list-labels")]
|
||||||
|
List(ListLabelCli),
|
||||||
|
/// Add label to rule
|
||||||
|
#[clap(name = "add-label")]
|
||||||
|
Add(AddLabelCli),
|
||||||
|
/// Remove a label from a
|
||||||
|
#[clap(name = "remove-label", alias = "rm-label")]
|
||||||
|
Remove(RemoveLabelCli),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
@@ -39,9 +48,11 @@ pub struct ConfigCli {
|
|||||||
impl ConfigCli {
|
impl ConfigCli {
|
||||||
pub fn run(&self, rules: Rules) -> Result<()> {
|
pub fn run(&self, rules: Rules) -> Result<()> {
|
||||||
match &self.sub_command {
|
match &self.sub_command {
|
||||||
SubCmds::Label(label_cli) => label_cli.run(rules),
|
SubCmds::ActionRule(action_cli) => action_cli.run(rules),
|
||||||
SubCmds::Action(action_cli) => action_cli.run(rules),
|
SubCmds::ListRules => rules.list_rules(),
|
||||||
SubCmds::List => rules.list_rules(),
|
SubCmds::AddRule(add_cli) => add_cli.run(rules),
|
||||||
|
SubCmds::RemoveRule(rm_cli) => rm_cli.run(rules),
|
||||||
|
SubCmds::List(list_cli) => list_cli.run(rules),
|
||||||
SubCmds::Add(add_cli) => add_cli.run(rules),
|
SubCmds::Add(add_cli) => add_cli.run(rules),
|
||||||
SubCmds::Remove(rm_cli) => rm_cli.run(rules),
|
SubCmds::Remove(rm_cli) => rm_cli.run(rules),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use clap::Parser;
|
|||||||
use cull_gmail::{Error, Result, Rules};
|
use cull_gmail::{Error, Result, Rules};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct AddCli {
|
pub struct AddLabelCli {
|
||||||
/// Id of the rule on which action applies
|
/// Id of the rule on which action applies
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
id: usize,
|
id: usize,
|
||||||
@@ -12,7 +12,7 @@ pub struct AddCli {
|
|||||||
label: String,
|
label: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddCli {
|
impl AddLabelCli {
|
||||||
pub fn run(&self, mut config: Rules) -> Result<()> {
|
pub fn run(&self, mut config: Rules) -> Result<()> {
|
||||||
if config.get_rule(self.id).is_none() {
|
if config.get_rule(self.id).is_none() {
|
||||||
return Err(Error::RuleNotFound(self.id));
|
return Err(Error::RuleNotFound(self.id));
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
use clap::{Parser, Subcommand};
|
|
||||||
use cull_gmail::{Error, Rules};
|
|
||||||
|
|
||||||
mod add_cli;
|
|
||||||
mod list_cli;
|
|
||||||
mod remove_cli;
|
|
||||||
|
|
||||||
use add_cli::AddCli;
|
|
||||||
use list_cli::ListCli;
|
|
||||||
use remove_cli::RemoveCli;
|
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
|
||||||
pub enum LabelCommands {
|
|
||||||
/// List the labels associated with a rule
|
|
||||||
#[clap(name = "list")]
|
|
||||||
List(ListCli),
|
|
||||||
/// Add label to rule
|
|
||||||
#[clap(name = "add")]
|
|
||||||
Add(AddCli),
|
|
||||||
/// Remove a label from a
|
|
||||||
#[clap(name = "remove", alias = "rm")]
|
|
||||||
Remove(RemoveCli),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
pub struct LabelCli {
|
|
||||||
/// Configuration commands
|
|
||||||
#[command(subcommand)]
|
|
||||||
command: LabelCommands,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LabelCli {
|
|
||||||
pub fn run(&self, config: Rules) -> Result<(), Error> {
|
|
||||||
match &self.command {
|
|
||||||
LabelCommands::List(list_cli) => list_cli.run(config),
|
|
||||||
LabelCommands::Add(add_cli) => add_cli.run(config),
|
|
||||||
LabelCommands::Remove(rm_cli) => rm_cli.run(config),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,13 +3,13 @@ use clap::Parser;
|
|||||||
use cull_gmail::{Error, Result, Rules};
|
use cull_gmail::{Error, Result, Rules};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct ListCli {
|
pub struct ListLabelCli {
|
||||||
/// Id of the rule on which action applies
|
/// Id of the rule on which action applies
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
id: usize,
|
id: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListCli {
|
impl ListLabelCli {
|
||||||
pub fn run(&self, config: Rules) -> Result<()> {
|
pub fn run(&self, config: Rules) -> Result<()> {
|
||||||
let Some(rule) = config.get_rule(self.id) else {
|
let Some(rule) = config.get_rule(self.id) else {
|
||||||
return Err(Error::RuleNotFound(self.id));
|
return Err(Error::RuleNotFound(self.id));
|
||||||
@@ -3,7 +3,7 @@ use clap::Parser;
|
|||||||
use cull_gmail::{Error, Result, Rules};
|
use cull_gmail::{Error, Result, Rules};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct RemoveCli {
|
pub struct RemoveLabelCli {
|
||||||
/// Id of the rule on which action applies
|
/// Id of the rule on which action applies
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
id: usize,
|
id: usize,
|
||||||
@@ -12,7 +12,7 @@ pub struct RemoveCli {
|
|||||||
label: String,
|
label: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RemoveCli {
|
impl RemoveLabelCli {
|
||||||
pub fn run(&self, mut config: Rules) -> Result<()> {
|
pub fn run(&self, mut config: Rules) -> Result<()> {
|
||||||
if config.get_rule(self.id).is_none() {
|
if config.get_rule(self.id).is_none() {
|
||||||
return Err(Error::RuleNotFound(self.id));
|
return Err(Error::RuleNotFound(self.id));
|
||||||
Reference in New Issue
Block a user