use std::path::PathBuf; // use clap::Parser; use color_eyre::Result; use crate::{execute::Execute, p, FullCtx}; use super::model::{attachment::TrelloAttachmentId, card::TrelloCardId}; #[derive(Parser, Debug)] pub enum TrelloAttachmentCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, card_id: String, attachment_id: String, }, Save { card_id: String, attachment_id: String, file_name: Option, // will use file name from attachment if not provided. }, } impl Execute for TrelloAttachmentCommand { async fn execute(&self, ctx: &FullCtx) -> Result<()> { match self { Self::Get { dump, card_id, attachment_id, } => { let trello_card_id = TrelloCardId::new(card_id); let trello_attachment_id = TrelloAttachmentId::new(attachment_id); let api_result = ctx .trello_client() .card_attachment(&trello_card_id, &trello_attachment_id) .await; if *dump { p!(ctx.prt, "{}", api_result.text); } else { let attachment = api_result.result?; p!(ctx.prt, "{}:{}", attachment.name, attachment.url); } Ok(()) } Self::Save { card_id, attachment_id, file_name, } => { let trello_card_id = TrelloCardId::new(card_id); let trello_attachment_id = TrelloAttachmentId::new(attachment_id); let file_name = ctx .trello_client() .save_attachment(&trello_card_id, &trello_attachment_id, file_name.as_ref()) .await?; p!(ctx.prt, "Wrote: {}", file_name.display()); Ok(()) } } } }