use crate::output::{OutputFormat, print_output};
use anyhow::Result;
use clap::{Args, Subcommand};
use grr_gmail::GmailClient;
#[derive(Subcommand, Debug)]
pub enum WatchCommands {
Start(StartArgs),
Stop(StopArgs),
}
#[derive(Args, Debug)]
pub struct StartArgs {
pub topic_name: String,
#[arg(long, value_delimiter = ',')]
pub label_ids: Option<Vec<String>>,
#[arg(short, long, value_enum, default_value = "json")]
pub format: OutputFormat,
}
#[derive(Args, Debug)]
pub struct StopArgs {
#[arg(short, long, value_enum, default_value = "json")]
pub format: OutputFormat,
}
pub async fn handle_watch_cmd(client: &GmailClient, cmd: WatchCommands) -> Result<()> {
match cmd {
WatchCommands::Start(args) => {
let response = client.watch(&args.topic_name, args.label_ids).await?;
print_output(&response, args.format)?;
}
WatchCommands::Stop(_args) => {
client.stop_watch().await?;
println!("Push notifications stopped");
}
}
Ok(())
}