2024-12-05 20:07:29 +00:00
|
|
|
//
|
2024-12-08 17:23:54 +00:00
|
|
|
use clap::Parser;
|
|
|
|
|
2024-12-08 22:31:37 +00:00
|
|
|
use crate::{
|
|
|
|
execute::Execute,
|
|
|
|
p,
|
|
|
|
trello::model::{board::TrelloBoard, TrelloBoardName},
|
|
|
|
FullCtx,
|
|
|
|
};
|
2024-12-05 20:07:29 +00:00
|
|
|
|
2024-12-08 17:23:54 +00:00
|
|
|
#[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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-05 20:07:29 +00:00
|
|
|
pub(crate) async fn list(ctx: FullCtx, dump: bool) -> color_eyre::Result<()> {
|
2024-12-08 17:23:54 +00:00
|
|
|
let api_result = ctx.trello_client().boards(&ctx.cfg.trello).await;
|
2024-12-05 20:07:29 +00:00
|
|
|
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(())
|
|
|
|
}
|
2024-11-30 18:04:48 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|