✨ feat(list): add label filtering to list command
- allow filtering messages by labels - add labels argument to list subcommand - update list command to use labels argument
This commit is contained in:
committed by
Jeremiah Russell
parent
f1ae06bf74
commit
f425c16422
@@ -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<String>,
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user