♻️ refactor(cli): rename command to sub_command for clarity
- rename `command` field to `sub_command` in `Cli` and `ConfigCli` structs
- rename `Commands` enum to `SubCmds` to reflect its role as subcommand
- update references to the renamed fields and enum variants
- this improves code readability and avoids confusion with other command concepts
🐛 fix(config): correct method name for setting eol action
- rename `set_command` to `set_action` in `EolRule` struct
- update references in `config.rs` to use the correct method name
- this fixes a bug where the eol action was not being set correctly
This commit is contained in:
committed by
Jeremiah Russell
parent
e80c7e3273
commit
40ea9e52f4
@@ -85,7 +85,7 @@ impl Config {
|
||||
rule.add_label(l);
|
||||
}
|
||||
if delete {
|
||||
rule.set_command(&EolAction::Delete);
|
||||
rule.set_action(&EolAction::Delete);
|
||||
}
|
||||
log::info!("added rule: {rule}");
|
||||
self.rules.insert(rule.id().to_string(), rule);
|
||||
@@ -178,7 +178,7 @@ impl Config {
|
||||
let Some(rule) = self.rules.get_mut(id.to_string().as_str()) else {
|
||||
return Err(Error::RuleNotFound(id));
|
||||
};
|
||||
rule.set_command(action);
|
||||
rule.set_action(action);
|
||||
self.save()?;
|
||||
println!("Action set to `{action}` on rule `#{id}`");
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ impl EolRule {
|
||||
self.labels.iter().map(|i| i.to_string()).collect()
|
||||
}
|
||||
|
||||
pub(crate) fn set_command(&mut self, value: &EolAction) -> &mut Self {
|
||||
pub(crate) fn set_action(&mut self, value: &EolAction) -> &mut Self {
|
||||
self.action = value.to_string();
|
||||
self
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use label_cli::LabelCli;
|
||||
use rules_cli::RulesCli;
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum Commands {
|
||||
enum SubCmds {
|
||||
/// Configure end-of-life rules
|
||||
#[clap(name = "rules")]
|
||||
Rules(RulesCli),
|
||||
@@ -27,15 +27,15 @@ pub struct ConfigCli {
|
||||
#[clap(flatten)]
|
||||
logging: clap_verbosity_flag::Verbosity,
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
sub_command: SubCmds,
|
||||
}
|
||||
|
||||
impl ConfigCli {
|
||||
pub fn run(&self, config: Config) -> Result<()> {
|
||||
match &self.command {
|
||||
Commands::Rules(rules_cli) => rules_cli.run(config),
|
||||
Commands::Label(label_cli) => label_cli.run(config),
|
||||
Commands::Action(action_cli) => action_cli.run(config),
|
||||
match &self.sub_command {
|
||||
SubCmds::Rules(rules_cli) => rules_cli.run(config),
|
||||
SubCmds::Label(label_cli) => label_cli.run(config),
|
||||
SubCmds::Action(action_cli) => action_cli.run(config),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::fmt;
|
||||
|
||||
/// End of life command
|
||||
/// End of life action
|
||||
/// - Trash - move the message to the trash to be automatically deleted by Google
|
||||
/// - Delete - delete the message immediately without allowing rescue from trash
|
||||
#[derive(Debug, Default)]
|
||||
|
||||
14
src/main.rs
14
src/main.rs
@@ -20,11 +20,11 @@ struct Cli {
|
||||
#[clap(flatten)]
|
||||
logging: clap_verbosity_flag::Verbosity,
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
sub_command: Option<SubCmds>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum Commands {
|
||||
enum SubCmds {
|
||||
/// List messages
|
||||
#[clap(name = "message")]
|
||||
Message(MessageCli),
|
||||
@@ -65,12 +65,12 @@ async fn main() {
|
||||
async fn run(args: Cli) -> Result<(), Error> {
|
||||
let config = get_config()?;
|
||||
log::trace!("Configuration loaded: {config:#?}");
|
||||
if let Some(cmds) = args.command {
|
||||
if let Some(cmds) = args.sub_command {
|
||||
match cmds {
|
||||
Commands::Message(list_cli) => list_cli.run(config.credential_file()).await?,
|
||||
Commands::Labels(label_cli) => label_cli.run(config.credential_file()).await?,
|
||||
Commands::Trash(trash_cli) => trash_cli.run(config.credential_file()).await?,
|
||||
Commands::Config(config_cli) => config_cli.run(config)?,
|
||||
SubCmds::Message(list_cli) => list_cli.run(config.credential_file()).await?,
|
||||
SubCmds::Labels(label_cli) => label_cli.run(config.credential_file()).await?,
|
||||
SubCmds::Trash(trash_cli) => trash_cli.run(config.credential_file()).await?,
|
||||
SubCmds::Config(config_cli) => config_cli.run(config)?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user