♻️ refactor(cli): refactor message handling and remove trash command
- 【Refactor】: Moved trash functionality into the message subcommand for better organization. - 【Refactor】: Removed the separate `trash_cli` module. - 【Feature】: Added a `Trash` action to the `MessageAction` enum. - 【Refactor】: Modified `MessageCli::run` to handle the new `Trash` action.
This commit is contained in:
committed by
Jeremiah Russell
parent
1052eeb22e
commit
f3a1edaf1f
@@ -6,7 +6,6 @@ mod label_cli;
|
||||
mod message_cli;
|
||||
mod message_trait;
|
||||
mod run_cli;
|
||||
mod trash_cli;
|
||||
|
||||
use cull_gmail::{Config, GmailClient, Result};
|
||||
use std::error::Error as stdError;
|
||||
@@ -16,7 +15,6 @@ use delete_cli::DeleteCli;
|
||||
use label_cli::LabelCli;
|
||||
use message_cli::MessageCli;
|
||||
use run_cli::RunCli;
|
||||
use trash_cli::TrashCli;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
@@ -42,10 +40,6 @@ enum SubCmds {
|
||||
/// List labels
|
||||
#[clap(name = "label", display_order = 2, next_help_heading = "Labels")]
|
||||
Labels(LabelCli),
|
||||
/// Move messages to trash
|
||||
#[clap(name = "trash", display_order = 4, next_help_heading = "Messages")]
|
||||
Trash(TrashCli),
|
||||
/// Delete messages
|
||||
#[clap(name = "delete", display_order = 5, next_help_heading = "Messages")]
|
||||
Delete(DeleteCli),
|
||||
/// Run the rules from the rules configuration
|
||||
@@ -86,7 +80,6 @@ async fn run(args: Cli) -> Result<()> {
|
||||
SubCmds::Config(config_cli) => config_cli.run(config),
|
||||
SubCmds::Message(list_cli) => list_cli.run(&mut client).await,
|
||||
SubCmds::Labels(label_cli) => label_cli.run(client).await,
|
||||
SubCmds::Trash(trash_cli) => trash_cli.run(&mut client).await,
|
||||
SubCmds::Delete(delete_cli) => delete_cli.run(&mut client).await,
|
||||
SubCmds::Run(run_cli) => run_cli.run(&mut client, config).await,
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use cull_gmail::{GmailClient, MessageList, Result};
|
||||
use cull_gmail::{GmailClient, MessageList, Result, RuleProcessor};
|
||||
|
||||
use crate::message_trait::Message;
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum MessageAction {
|
||||
List,
|
||||
Trash,
|
||||
}
|
||||
|
||||
/// Command line options for the list subcommand
|
||||
@@ -43,12 +44,15 @@ impl MessageCli {
|
||||
match self.action {
|
||||
MessageAction::List => {
|
||||
if log::max_level() >= log::Level::Info {
|
||||
client.log_message_subjects().await?;
|
||||
client.log_message_subjects().await
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
MessageAction::Trash => client.batch_trash().await,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
// Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn labels(&self) -> &Vec<String> {
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
use clap::Parser;
|
||||
use cull_gmail::{Error, GmailClient, MessageList, RuleProcessor};
|
||||
|
||||
/// Command line options for the list subcommand
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct TrashCli {
|
||||
/// Maximum results per page
|
||||
#[arg(short, long, default_value = cull_gmail::DEFAULT_MAX_RESULTS)]
|
||||
max_results: u32,
|
||||
/// Maximum number of pages (0=all)
|
||||
#[arg(short, long, default_value = "1")]
|
||||
pages: u32,
|
||||
/// Labels to filter the message list
|
||||
#[arg(short, long)]
|
||||
labels: Vec<String>,
|
||||
/// Query string to select messages to list
|
||||
#[arg(short = 'Q', long)]
|
||||
query: Option<String>,
|
||||
}
|
||||
|
||||
impl TrashCli {
|
||||
pub(crate) async fn run(&self, client: &mut GmailClient) -> Result<(), Error> {
|
||||
if !self.labels.is_empty() {
|
||||
// add labels if any specified
|
||||
client.add_labels(&self.labels)?;
|
||||
}
|
||||
|
||||
if let Some(query) = self.query.as_ref() {
|
||||
client.set_query(query)
|
||||
}
|
||||
|
||||
log::trace!("Max results: `{}`", self.max_results);
|
||||
client.set_max_results(self.max_results);
|
||||
log::debug!("List max results set to {}", client.max_results());
|
||||
|
||||
client.prepare(self.pages).await?;
|
||||
client.batch_trash().await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user