trello-to-deck/src/trello/boards.rs

49 lines
1.2 KiB
Rust
Raw Normal View History

//
use clap::Parser;
use crate::{
execute::Execute,
p,
trello::model::{board::TrelloBoard, TrelloBoardName},
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<TrelloBoard> {
fn find_by_name(&self, board_name: &TrelloBoardName) -> Option<&TrelloBoard> {
self.iter().find(|b| &b.name == board_name)
}
}