diff --git a/src/check.rs b/src/check.rs index 642f41a..6d6fa0c 100644 --- a/src/check.rs +++ b/src/check.rs @@ -3,7 +3,7 @@ use color_eyre::eyre::{OptionExt as _, Result}; use crate::{f, p, trello::model::board::TrelloBoards as _, FullCtx}; -pub(crate) async fn run(ctx: FullCtx) -> Result<()> { +pub(crate) async fn run(ctx: &FullCtx) -> Result<()> { { // test trello by getting a list of the boards for the user p!(ctx.prt, ">> Testing Trello details..."); diff --git a/src/execute.rs b/src/execute.rs index 401ab11..f99dd45 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -5,11 +5,11 @@ use color_eyre::Result; use crate::FullCtx; pub(crate) trait Execute { - async fn execute(self, ctx: FullCtx) -> Result<()>; + async fn execute(self, ctx: &FullCtx) -> Result<()>; } impl Execute for crate::Command { - async fn execute(self, ctx: FullCtx) -> Result<()> { + async fn execute(self, ctx: &FullCtx) -> Result<()> { match self { Self::Init => Err(eyre!("Config file already exists. Not overwriting it.")), Self::Check => crate::check::run(ctx).await, diff --git a/src/lib.rs b/src/lib.rs index 1d2600c..13121f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,7 +95,7 @@ impl FullCtx { } #[cfg_attr(test, mutants::skip)] -pub async fn run(ctx: Ctx) -> color_eyre::Result<()> { +pub async fn run(ctx: &Ctx) -> color_eyre::Result<()> { color_eyre::install()?; let commands = Commands::parse(); @@ -108,11 +108,11 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> { tracing::info!("ready"); } - let cfg = AppConfig::load(&ctx); + let cfg = AppConfig::load(ctx); match cfg { Err(err) => { if matches!(commands.command, Command::Init) { - init::run(&ctx) + init::run(ctx) } else { Err(eyre!("Missing or invalid config: {err}")) } @@ -120,10 +120,10 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> { Ok(cfg) => { commands .command - .execute(FullCtx { - fs: ctx.fs, - net: ctx.net, - prt: ctx.prt, + .execute(&FullCtx { + fs: ctx.fs.clone(), + net: ctx.net.clone(), + prt: ctx.prt.clone(), cfg, }) .await diff --git a/src/main.rs b/src/main.rs index e28dab2..7cbe615 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,5 +6,5 @@ use trello_to_deck::{run, Ctx}; #[tokio::main] #[cfg_attr(test, mutants::skip)] async fn main() -> Result<()> { - run(Ctx::from(std::env::current_dir()?)).await + run(&Ctx::from(std::env::current_dir()?)).await } diff --git a/src/nextcloud/card.rs b/src/nextcloud/card.rs index 888ad7a..a798111 100644 --- a/src/nextcloud/card.rs +++ b/src/nextcloud/card.rs @@ -41,10 +41,10 @@ pub(crate) enum NextcloudCardCommand { } impl Execute for NextcloudCardCommand { - async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + async fn execute(self, ctx: &FullCtx) -> color_eyre::Result<()> { match self { Self::List { dump, stack_id } => { - list(&ctx, dump, NextcloudStackId::from(stack_id)).await + list(ctx, dump, NextcloudStackId::from(stack_id)).await } Self::Get { dump, @@ -52,7 +52,7 @@ impl Execute for NextcloudCardCommand { card_id, } => { get( - &ctx, + ctx, dump, NextcloudStackId::from(stack_id), NextcloudCardId::from(card_id), @@ -143,7 +143,7 @@ pub(crate) struct Create { pub(crate) title: String, pub(crate) description: Option, } -pub(crate) async fn create(ctx: FullCtx, create: Create) -> color_eyre::Result<()> { +pub(crate) async fn create(ctx: &FullCtx, create: Create) -> color_eyre::Result<()> { let api_result = ctx.deck_client().create_card(&create).await; if create.dump { p!(ctx.prt, "{}", api_result.text); @@ -160,7 +160,7 @@ pub(crate) struct AddLabel { pub(crate) card_id: NextcloudCardId, pub(crate) label_id: NextcloudLabelId, } -async fn add_label(ctx: FullCtx, add_label: AddLabel) -> color_eyre::Result<()> { +async fn add_label(ctx: &FullCtx, add_label: AddLabel) -> color_eyre::Result<()> { let api_result = ctx.deck_client().add_label_to_card(&add_label).await; if add_label.dump { p!(ctx.prt, "{}", api_result.text); diff --git a/src/nextcloud/deck.rs b/src/nextcloud/deck.rs index 32cb3eb..ef31024 100644 --- a/src/nextcloud/deck.rs +++ b/src/nextcloud/deck.rs @@ -13,7 +13,7 @@ pub(crate) enum NextcloudDeckCommand { } impl Execute for NextcloudDeckCommand { - async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + async fn execute(self, ctx: &FullCtx) -> color_eyre::Result<()> { match self { Self::Get { dump } => { let api_result = ctx.deck_client().get_boards().await; diff --git a/src/nextcloud/mod.rs b/src/nextcloud/mod.rs index 9044e85..c63d0fe 100644 --- a/src/nextcloud/mod.rs +++ b/src/nextcloud/mod.rs @@ -38,7 +38,7 @@ pub(crate) enum NextcloudCommand { Card(NextcloudCardCommand), } impl Execute for NextcloudCommand { - async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + async fn execute(self, ctx: &FullCtx) -> color_eyre::Result<()> { match self { NextcloudCommand::Deck(cmd) => cmd.execute(ctx).await, NextcloudCommand::Stack(cmd) => cmd.execute(ctx).await, diff --git a/src/nextcloud/stack.rs b/src/nextcloud/stack.rs index c9c9481..129057c 100644 --- a/src/nextcloud/stack.rs +++ b/src/nextcloud/stack.rs @@ -13,14 +13,14 @@ pub(crate) enum NextcloudStackCommand { } impl Execute for NextcloudStackCommand { - async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + 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<()> { +pub(crate) async fn list(ctx: &FullCtx, dump: bool) -> color_eyre::Result<()> { let api_result = ctx .deck_client() .get_stacks(ctx.cfg.nextcloud.board_id) diff --git a/src/nextcloud/tests/card/add_label.rs b/src/nextcloud/tests/card/add_label.rs index 969aa62..b554396 100644 --- a/src/nextcloud/tests/card/add_label.rs +++ b/src/nextcloud/tests/card/add_label.rs @@ -63,7 +63,7 @@ async fn dump( card_id: card_id.into(), label_id: label_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -91,7 +91,7 @@ async fn no_dump( card_id: card_id.into(), label_id: label_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/nextcloud/tests/card/create.rs b/src/nextcloud/tests/card/create.rs index 3d2d54b..ba24ccf 100644 --- a/src/nextcloud/tests/card/create.rs +++ b/src/nextcloud/tests/card/create.rs @@ -52,7 +52,7 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, #[case] description: Opt title: "my new card".to_string(), description, })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -80,7 +80,7 @@ async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, #[case] description: title: "my new card".to_string(), description, })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/nextcloud/tests/card/get.rs b/src/nextcloud/tests/card/get.rs index f5ae7c9..f88d6f6 100644 --- a/src/nextcloud/tests/card/get.rs +++ b/src/nextcloud/tests/card/get.rs @@ -54,7 +54,7 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId stack_id: stack_id.into(), card_id: card_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -79,7 +79,7 @@ async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCar stack_id: stack_id.into(), card_id: card_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/nextcloud/tests/card/list.rs b/src/nextcloud/tests/card/list.rs index 69f11ee..d841d55 100644 --- a/src/nextcloud/tests/card/list.rs +++ b/src/nextcloud/tests/card/list.rs @@ -48,7 +48,7 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId) { dump: true, stack_id: stack_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -72,7 +72,7 @@ async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId) { dump: false, stack_id: stack_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/nextcloud/tests/deck/get.rs b/src/nextcloud/tests/deck/get.rs index f9ba1ca..541c075 100644 --- a/src/nextcloud/tests/deck/get.rs +++ b/src/nextcloud/tests/deck/get.rs @@ -41,7 +41,7 @@ async fn dump(ctx: FullCtx) { Command::Nextcloud(NextcloudCommand::Deck(NextcloudDeckCommand::Get { dump: true, })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -64,7 +64,7 @@ async fn no_dump(ctx: FullCtx) { Command::Nextcloud(NextcloudCommand::Deck(NextcloudDeckCommand::Get { dump: false, })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/nextcloud/tests/stack/list.rs b/src/nextcloud/tests/stack/list.rs index 7b4e1aa..01b5cb4 100644 --- a/src/nextcloud/tests/stack/list.rs +++ b/src/nextcloud/tests/stack/list.rs @@ -37,7 +37,7 @@ async fn dump(ctx: FullCtx) { let prt = prt.as_test().unwrap(); //when - crate::nextcloud::stack::list(ctx, true) + crate::nextcloud::stack::list(&ctx, true) .await .expect("execute"); @@ -60,7 +60,7 @@ async fn no_dump(ctx: FullCtx) { Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::List { dump: false, })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/trello/attachment.rs b/src/trello/attachment.rs index 4ec8644..656884f 100644 --- a/src/trello/attachment.rs +++ b/src/trello/attachment.rs @@ -25,7 +25,7 @@ pub(crate) enum TrelloAttachmentCommand { } impl Execute for TrelloAttachmentCommand { - async fn execute(self, ctx: FullCtx) -> Result<()> { + async fn execute(self, ctx: &FullCtx) -> Result<()> { match self { Self::Get { dump, diff --git a/src/trello/board.rs b/src/trello/board.rs index be57dfc..d9e54d3 100644 --- a/src/trello/board.rs +++ b/src/trello/board.rs @@ -17,7 +17,7 @@ pub(crate) enum TrelloBoardCommand { } impl Execute for TrelloBoardCommand { - async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + async fn execute(self, ctx: &FullCtx) -> color_eyre::Result<()> { match self { Self::Get { dump, board_id } => { let api_result = ctx diff --git a/src/trello/card.rs b/src/trello/card.rs index 1e595db..ff8a375 100644 --- a/src/trello/card.rs +++ b/src/trello/card.rs @@ -17,7 +17,7 @@ pub(crate) enum TrelloCardCommand { } impl Execute for TrelloCardCommand { - async fn execute(self, ctx: FullCtx) -> Result<()> { + async fn execute(self, ctx: &FullCtx) -> Result<()> { match self { Self::Get { dump, card_id } => { let api_result = ctx.trello_client().card(&TrelloCardId::new(card_id)).await; diff --git a/src/trello/member.rs b/src/trello/member.rs index 591ac3d..170e19c 100644 --- a/src/trello/member.rs +++ b/src/trello/member.rs @@ -13,7 +13,7 @@ pub(crate) enum TrelloMemberCommand { } impl Execute for TrelloMemberCommand { - async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + async fn execute(self, ctx: &FullCtx) -> color_eyre::Result<()> { match self { Self::Get { dump } => { let api_result = ctx.trello_client().boards().await; diff --git a/src/trello/mod.rs b/src/trello/mod.rs index 0fe89ba..abe1785 100644 --- a/src/trello/mod.rs +++ b/src/trello/mod.rs @@ -47,7 +47,7 @@ pub(crate) enum TrelloCommand { } impl Execute for TrelloCommand { - async fn execute(self, ctx: FullCtx) -> color_eyre::Result<()> { + async fn execute(self, ctx: &FullCtx) -> color_eyre::Result<()> { match self { Self::Member(cmd) => cmd.execute(ctx).await, Self::Board(cmd) => cmd.execute(ctx).await, diff --git a/src/trello/stack.rs b/src/trello/stack.rs index 7191f7b..420f576 100644 --- a/src/trello/stack.rs +++ b/src/trello/stack.rs @@ -17,7 +17,7 @@ pub(crate) enum TrelloStackCommand { } impl Execute for TrelloStackCommand { - async fn execute(self, ctx: FullCtx) -> Result<()> { + async fn execute(self, ctx: &FullCtx) -> Result<()> { match self { Self::Get { dump, list_id } => { let api_result = ctx diff --git a/src/trello/tests/attachment/get.rs b/src/trello/tests/attachment/get.rs index dec8344..a5f8c94 100644 --- a/src/trello/tests/attachment/get.rs +++ b/src/trello/tests/attachment/get.rs @@ -70,7 +70,7 @@ async fn dump(ctx: FullCtx, card_id: TrelloCardId, attachment_id: TrelloAttachme card_id: card_id.into(), attachment_id: attachment_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -95,7 +95,7 @@ async fn no_dump(ctx: FullCtx, card_id: TrelloCardId, attachment_id: TrelloAttac card_id: card_id.into(), attachment_id: attachment_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/trello/tests/attachment/save.rs b/src/trello/tests/attachment/save.rs index 6af388c..3195d33 100644 --- a/src/trello/tests/attachment/save.rs +++ b/src/trello/tests/attachment/save.rs @@ -104,7 +104,7 @@ async fn save( attachment_id: attachment_id.into(), file_name: None, // Case? })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/trello/tests/board/get.rs b/src/trello/tests/board/get.rs index b6b1bf2..02c4a52 100644 --- a/src/trello/tests/board/get.rs +++ b/src/trello/tests/board/get.rs @@ -56,7 +56,7 @@ async fn dump(ctx: FullCtx, board_id: TrelloBoardId) { dump: true, board_id: board_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -80,7 +80,7 @@ async fn no_dump(ctx: FullCtx, board_id: TrelloBoardId) { dump: false, board_id: board_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/trello/tests/card/get.rs b/src/trello/tests/card/get.rs index d672039..488be6d 100644 --- a/src/trello/tests/card/get.rs +++ b/src/trello/tests/card/get.rs @@ -56,7 +56,7 @@ async fn dump(ctx: FullCtx, card_id: TrelloCardId) { dump: true, card_id: card_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -80,7 +80,7 @@ async fn no_dump(ctx: FullCtx, card_id: TrelloCardId) { dump: false, card_id: card_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/trello/tests/member/get.rs b/src/trello/tests/member/get.rs index 4811db4..fd0de4d 100644 --- a/src/trello/tests/member/get.rs +++ b/src/trello/tests/member/get.rs @@ -47,7 +47,7 @@ async fn dump(ctx: FullCtx) { Command::Trello(TrelloCommand::Member(TrelloMemberCommand::Get { dump: true, })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -70,7 +70,7 @@ async fn no_dump(ctx: FullCtx) { Command::Trello(TrelloCommand::Member(TrelloMemberCommand::Get { dump: false, })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); diff --git a/src/trello/tests/stack/get.rs b/src/trello/tests/stack/get.rs index 1ba4705..6962d2b 100644 --- a/src/trello/tests/stack/get.rs +++ b/src/trello/tests/stack/get.rs @@ -57,7 +57,7 @@ async fn dump(ctx: FullCtx, list_id: TrelloListId) { dump: true, list_id: list_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute"); @@ -81,7 +81,7 @@ async fn no_dump(ctx: FullCtx, list_id: TrelloListId) { dump: false, list_id: list_id.into(), })) - .execute(ctx) + .execute(&ctx) .await .expect("execute");