From 6832c22d3da6c254da7acccfd15eef3c55e5a5dc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 8 Dec 2024 07:24:44 +0000 Subject: [PATCH] refactor: rearrange command dispatcher --- src/lib.rs | 47 +++++++++++++++++++++++++++----------------- src/trello/boards.rs | 34 ++++++++++++++++---------------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b0b301..7df25b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,24 +150,35 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> { Command::Init => Err(eyre!("Config file already exists. Not overwriting it.")), Command::Check => check::run(ctx).await, Command::Import => todo!("import"), - Command::Trello(TrelloCommand::Board(TrelloBoardCommand::List { dump })) => { - trello::boards::list(ctx, dump).await - } - Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::List { - dump, - })) => nextcloud::board::list(ctx, dump).await, - Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::List { - dump, - })) => nextcloud::stack::list(ctx, dump).await, - Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::List { - dump, - stack_id, - })) => nextcloud::card::list(ctx, dump, stack_id.into()).await, - Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get { - dump, - stack_id, - card_id, - })) => nextcloud::card::get(ctx, dump, stack_id.into(), card_id.into()).await, + Command::Trello(trello) => match trello { + TrelloCommand::Board(board) => match board { + TrelloBoardCommand::List { dump } => { + nextcloud::board::list(ctx, dump).await + } + }, + }, + Command::Nextcloud(nextcloud) => match nextcloud { + NextcloudCommand::Board(board) => match board { + NextcloudBoardCommand::List { dump } => { + nextcloud::board::list(ctx, dump).await + } + }, + NextcloudCommand::Stack(stack) => match stack { + NextcloudStackCommand::List { dump } => { + nextcloud::stack::list(ctx, dump).await + } + }, + NextcloudCommand::Card(card) => match card { + NextcloudCardCommand::List { dump, stack_id } => { + nextcloud::card::list(ctx, dump, stack_id.into()).await + } + NextcloudCardCommand::Get { + dump, + stack_id, + card_id, + } => nextcloud::card::get(ctx, dump, stack_id.into(), card_id.into()).await, + }, + }, } } } diff --git a/src/trello/boards.rs b/src/trello/boards.rs index 3c50a13..d80607f 100644 --- a/src/trello/boards.rs +++ b/src/trello/boards.rs @@ -1,18 +1,18 @@ // -use crate::{p, FullCtx}; - -pub(crate) async fn list(ctx: FullCtx, dump: bool) -> color_eyre::Result<()> { - let api_result = - super::api::members::get_boards_that_member_belongs_to(&ctx.cfg.trello, &ctx.net, &ctx.prt) - .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(()) -} +// use crate::{p, FullCtx}; +// +// pub(crate) async fn list(ctx: FullCtx, dump: bool) -> color_eyre::Result<()> { +// let api_result = +// super::api::members::get_boards_that_member_belongs_to(&ctx.cfg.trello, &ctx.net, &ctx.prt) +// .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(()) +// }