✨ feat(cli): enhance rules configuration
- introduce subcommands for listing, adding, and removing rules - improve cli structure for better user experience
This commit is contained in:
committed by
Jeremiah Russell
parent
f0a5dde809
commit
b10dcbf8a9
@@ -1,19 +1,25 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
mod action_cli;
|
mod action_cli;
|
||||||
|
mod add_cli;
|
||||||
mod label_cli;
|
mod label_cli;
|
||||||
mod rules_cli;
|
mod rm_cli;
|
||||||
|
|
||||||
use action_cli::ActionCli;
|
use action_cli::ActionCli;
|
||||||
use cull_gmail::{Result, Rules};
|
use cull_gmail::{Result, Rules};
|
||||||
use label_cli::LabelCli;
|
use label_cli::LabelCli;
|
||||||
use rules_cli::RulesCli;
|
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum SubCmds {
|
enum SubCmds {
|
||||||
/// Configure end-of-life rules
|
/// List the rules configured and saved in the config file
|
||||||
#[clap(name = "rules")]
|
#[clap(name = "list")]
|
||||||
Rules(RulesCli),
|
List,
|
||||||
|
/// Add a rules to the config file
|
||||||
|
#[clap(name = "add")]
|
||||||
|
Add(add_cli::AddCli),
|
||||||
|
/// Remove a rule from the config file
|
||||||
|
#[clap(name = "remove", alias = "rm")]
|
||||||
|
Remove(rm_cli::RmCli),
|
||||||
/// Add or remove Label from rule
|
/// Add or remove Label from rule
|
||||||
#[clap(name = "label")]
|
#[clap(name = "label")]
|
||||||
Label(LabelCli),
|
Label(LabelCli),
|
||||||
@@ -33,9 +39,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::Rules(rules_cli) => rules_cli.run(rules),
|
|
||||||
SubCmds::Label(label_cli) => label_cli.run(rules),
|
SubCmds::Label(label_cli) => label_cli.run(rules),
|
||||||
SubCmds::Action(action_cli) => action_cli.run(rules),
|
SubCmds::Action(action_cli) => action_cli.run(rules),
|
||||||
|
SubCmds::List => rules.list_rules(),
|
||||||
|
SubCmds::Add(add_cli) => add_cli.run(rules),
|
||||||
|
SubCmds::Remove(rm_cli) => rm_cli.run(rules),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
use clap::{Parser, Subcommand};
|
|
||||||
use cull_gmail::{Error, Rules};
|
|
||||||
|
|
||||||
mod add_cli;
|
|
||||||
mod rm_cli;
|
|
||||||
|
|
||||||
use add_cli::AddCli;
|
|
||||||
use rm_cli::RmCli;
|
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
|
||||||
pub enum RulesCommands {
|
|
||||||
/// List the rules configured and saved in the config file
|
|
||||||
#[clap(name = "list")]
|
|
||||||
List,
|
|
||||||
/// Add a rules to the config file
|
|
||||||
#[clap(name = "add")]
|
|
||||||
Add(AddCli),
|
|
||||||
/// Remove a rule from the config file
|
|
||||||
#[clap(name = "remove", alias = "rm")]
|
|
||||||
Remove(RmCli),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
|
||||||
pub struct RulesCli {
|
|
||||||
/// Configuration commands
|
|
||||||
#[command(subcommand)]
|
|
||||||
command: RulesCommands,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RulesCli {
|
|
||||||
pub fn run(&self, config: Rules) -> Result<(), Error> {
|
|
||||||
match &self.command {
|
|
||||||
RulesCommands::List => config.list_rules(),
|
|
||||||
RulesCommands::Add(add_cli) => add_cli.run(config),
|
|
||||||
RulesCommands::Remove(rm_cli) => rm_cli.run(config),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user