diff --git a/README.md b/README.md index 8164d28..6eb1b4c 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ trello-to-deck check As part of building the import server, I'm including the following commands the exercise each operation invovled. -- [ ] trello member get (was boards list) +- [x] trello member get - [ ] trello board get (was list/stack list) - [ ] trello stack get (was card list) - [ ] trello card get diff --git a/src/trello/member.rs b/src/trello/member.rs new file mode 100644 index 0000000..e5f1b16 --- /dev/null +++ b/src/trello/member.rs @@ -0,0 +1,33 @@ +// +use clap::Parser; + +use crate::execute::Execute; +use crate::{p, FullCtx}; + +#[derive(Parser, Debug)] +pub(crate) enum TrelloMemberCommand { + Get { + #[clap(long, action = clap::ArgAction::SetTrue)] + dump: bool, + }, +} + +impl Execute for TrelloMemberCommand { + async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + match self { + Self::Get { dump } => { + 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(()) + } + } + } +} diff --git a/src/trello/mod.rs b/src/trello/mod.rs index 4e8ca9b..27986eb 100644 --- a/src/trello/mod.rs +++ b/src/trello/mod.rs @@ -2,25 +2,19 @@ pub(crate) mod api; pub(crate) mod boards; pub(crate) mod client; +pub(crate) mod member; pub(crate) mod model; pub(crate) mod stack; #[cfg(test)] mod tests; -use crate::{ - execute::Execute, - f, - trello::{ - boards::TrelloBoardCommand, - model::{ - auth::{TrelloApiKey, TrelloApiSecret}, - TrelloBoardName, - }, - stack::TrelloStackCommand, - }, - FullCtx, -}; +use crate::execute::Execute; +use crate::trello::member::TrelloMemberCommand; +use crate::trello::model::auth::{TrelloApiKey, TrelloApiSecret}; +use crate::trello::model::TrelloBoardName; +use crate::trello::stack::TrelloStackCommand; +use crate::{f, FullCtx}; use clap::Parser; @@ -33,7 +27,7 @@ pub(crate) fn url(path: impl Into) -> String { #[derive(Parser, Debug)] pub(crate) enum TrelloCommand { #[clap(subcommand)] - Board(TrelloBoardCommand), + Member(TrelloMemberCommand), #[clap(subcommand)] Stack(TrelloStackCommand), @@ -42,7 +36,7 @@ pub(crate) enum TrelloCommand { impl Execute for TrelloCommand { async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { match self { - Self::Board(cmd) => cmd.execute(ctx).await, + Self::Member(cmd) => cmd.execute(ctx).await, Self::Stack(cmd) => cmd.execute(ctx).await, } }