♻️ refactor(cli): rename rule management subcommands for clarity
- rename `add`, `rm`, and `action` subcommands to `add-rule`, `remove-rule`, and `set-action-on-rule` respectively to improve clarity - update corresponding modules and structs to reflect the renaming, enhancing code readability and maintainability
This commit is contained in:
committed by
Jeremiah Russell
parent
b64b2d00bd
commit
9773327e86
@@ -1,11 +1,11 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
mod action_cli;
|
mod action_rule_cli;
|
||||||
mod add_cli;
|
mod add_rule_cli;
|
||||||
mod label_cli;
|
mod label_cli;
|
||||||
mod rm_cli;
|
mod rm_rule_cli;
|
||||||
|
|
||||||
use action_cli::ActionCli;
|
use action_rule_cli::ActionRuleCli;
|
||||||
use cull_gmail::{Result, Rules};
|
use cull_gmail::{Result, Rules};
|
||||||
use label_cli::LabelCli;
|
use label_cli::LabelCli;
|
||||||
|
|
||||||
@@ -15,17 +15,17 @@ enum SubCmds {
|
|||||||
#[clap(name = "list")]
|
#[clap(name = "list")]
|
||||||
List,
|
List,
|
||||||
/// Add a rules to the config file
|
/// Add a rules to the config file
|
||||||
#[clap(name = "add")]
|
#[clap(name = "add-rule")]
|
||||||
Add(add_cli::AddCli),
|
Add(add_rule_cli::AddRuleCli),
|
||||||
/// Remove a rule from the config file
|
/// Remove a rule from the config file
|
||||||
#[clap(name = "remove", alias = "rm")]
|
#[clap(name = "remove-rule", alias = "rm")]
|
||||||
Remove(rm_cli::RmCli),
|
Remove(rm_rule_cli::RmRuleCli),
|
||||||
/// Add or remove Label from rule
|
/// Add or remove Label from rule
|
||||||
#[clap(name = "label")]
|
#[clap(name = "label")]
|
||||||
Label(LabelCli),
|
Label(LabelCli),
|
||||||
/// Set action on a specific rule
|
/// Set action on a specific rule
|
||||||
#[clap(name = "action")]
|
#[clap(name = "set-action-on-rule")]
|
||||||
Action(ActionCli),
|
Action(ActionRuleCli),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub enum Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct ActionCli {
|
pub struct ActionRuleCli {
|
||||||
/// 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,
|
||||||
@@ -21,7 +21,7 @@ pub struct ActionCli {
|
|||||||
action: Action,
|
action: Action,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActionCli {
|
impl ActionRuleCli {
|
||||||
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));
|
||||||
@@ -23,7 +23,7 @@ impl fmt::Display for Period {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct AddCli {
|
pub struct AddRuleCli {
|
||||||
/// Period for the rule
|
/// Period for the rule
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
period: Period,
|
period: Period,
|
||||||
@@ -38,7 +38,7 @@ pub struct AddCli {
|
|||||||
delete: bool,
|
delete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddCli {
|
impl AddRuleCli {
|
||||||
pub fn run(&self, mut config: Rules) -> Result<(), Error> {
|
pub fn run(&self, mut config: Rules) -> Result<(), Error> {
|
||||||
let generate = self.label.is_none();
|
let generate = self.label.is_none();
|
||||||
let message_age = MessageAge::new(self.period.to_string().as_str(), self.count)?;
|
let message_age = MessageAge::new(self.period.to_string().as_str(), self.count)?;
|
||||||
@@ -2,7 +2,7 @@ use clap::Parser;
|
|||||||
use cull_gmail::{Error, Rules};
|
use cull_gmail::{Error, Rules};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct RmCli {
|
pub struct RmRuleCli {
|
||||||
/// Id of the rule to remove
|
/// Id of the rule to remove
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
id: Option<usize>,
|
id: Option<usize>,
|
||||||
@@ -11,7 +11,7 @@ pub struct RmCli {
|
|||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RmCli {
|
impl RmRuleCli {
|
||||||
pub fn run(&self, mut config: Rules) -> Result<(), Error> {
|
pub fn run(&self, mut config: Rules) -> Result<(), Error> {
|
||||||
if self.id.is_none() && self.label.is_none() {
|
if self.id.is_none() && self.label.is_none() {
|
||||||
return Err(Error::NoRuleSelector);
|
return Err(Error::NoRuleSelector);
|
||||||
Reference in New Issue
Block a user