From f425c1642229e18fa771f228b43f780af3381ac6 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Fri, 3 Oct 2025 14:34:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(list):=20add=20label=20filteri?= =?UTF-8?q?ng=20to=20list=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - allow filtering messages by labels - add labels argument to list subcommand - update list command to use labels argument --- src/list_cli.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/list_cli.rs b/src/list_cli.rs index d46dca1..11c3e4a 100644 --- a/src/list_cli.rs +++ b/src/list_cli.rs @@ -1,5 +1,5 @@ use clap::Parser; -use cull_gmail::{Error, List}; +use cull_gmail::{Error, Labels, List}; /// Command line options for the list subcommand #[derive(Debug, Parser)] @@ -10,13 +10,28 @@ pub struct ListCli { /// 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, } impl ListCli { pub(crate) async fn run(&self, credential_file: &str) -> Result<(), Error> { - log::debug!("Max results: `{}`", self.max_results); + let mut labels = Labels::new(credential_file).await?; + labels.get_labels().await?; + log::trace!("labels found and setup {labels:#?}"); let mut list = List::new(credential_file).await?; + log::debug!("labels from command line: {:?}", self.labels); + + for label in &self.labels { + if let Some(l) = labels.get_label_id(label) { + log::trace!("adding `{l}` id to labels"); + list.add_label(&l); + } + } + + log::trace!("Max results: `{}`", self.max_results); list.set_max_results(self.max_results); log::debug!("List max results set to {}", list.max_results());