✨ feat(cli): add message list subcommand
- add subcommand to list messages from gmail - implement message listing functionality - add ability to specify query and number of pages
This commit is contained in:
committed by
Jeremiah Russell
parent
1eefad2cff
commit
02e58275e7
@@ -1,8 +1,13 @@
|
|||||||
use clap::Parser;
|
use clap::{Parser, Subcommand};
|
||||||
use cull_gmail::{GmailClient, MessageList, Result};
|
use cull_gmail::{GmailClient, MessageList, Result};
|
||||||
|
|
||||||
use crate::message_trait::Message;
|
use crate::message_trait::Message;
|
||||||
|
|
||||||
|
#[derive(Debug, Subcommand)]
|
||||||
|
enum MessageAction {
|
||||||
|
List,
|
||||||
|
}
|
||||||
|
|
||||||
/// Command line options for the list subcommand
|
/// Command line options for the list subcommand
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct MessageCli {
|
pub struct MessageCli {
|
||||||
@@ -24,13 +29,26 @@ pub struct MessageCli {
|
|||||||
/// Query string to select messages to list
|
/// Query string to select messages to list
|
||||||
#[arg(short = 'Q', long, display_order = 1, help_heading = "Config")]
|
#[arg(short = 'Q', long, display_order = 1, help_heading = "Config")]
|
||||||
query: Option<String>,
|
query: Option<String>,
|
||||||
|
/// Action: what to do with the message list
|
||||||
|
#[command(subcommand)]
|
||||||
|
action: MessageAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageCli {
|
impl MessageCli {
|
||||||
pub(crate) async fn run(&self, client: &mut GmailClient) -> Result<()> {
|
pub(crate) async fn run(&self, client: &mut GmailClient) -> Result<()> {
|
||||||
self.set_parameters(client)?;
|
self.set_parameters(client)?;
|
||||||
|
|
||||||
client.get_messages(self.pages).await
|
client.get_messages(self.pages).await?;
|
||||||
|
|
||||||
|
match self.action {
|
||||||
|
MessageAction::List => {
|
||||||
|
if log::max_level() >= log::Level::Info {
|
||||||
|
client.log_message_subjects().await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn labels(&self) -> &Vec<String> {
|
pub(crate) fn labels(&self) -> &Vec<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user