// use clap::Parser; use crate::execute::Execute; use crate::trello::types::board::TrelloBoard; use crate::trello::types::TrelloBoardName; use crate::{p, FullCtx}; #[derive(Parser, Debug)] pub(crate) enum TrelloBoardCommand { List { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, }, } impl Execute for TrelloBoardCommand { async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { match self { Self::List { dump } => list(ctx, dump).await, } } } pub(crate) async fn list(ctx: FullCtx, dump: bool) -> color_eyre::Result<()> { let api_result = ctx.trello_client().boards(&ctx.cfg.trello).await; if dump { p!(ctx.prt, "{}", api_result.text); } else { let mut boards = api_result.result?; boards.sort_by(|a, b| a.name.cmp(&b.name)); boards.into_iter().for_each(|board| { p!(ctx.prt, "{}:{}", board.id, board.name); }); } Ok(()) } pub trait TrelloBoards { fn find_by_name(&self, board_name: &TrelloBoardName) -> Option<&TrelloBoard>; } impl TrelloBoards for Vec { fn find_by_name(&self, board_name: &TrelloBoardName) -> Option<&TrelloBoard> { self.iter().find(|b| &b.name == board_name) } }