refactor: Execute::execute passes itself by ref
Some checks failed
Test / build (map[name:stable]) (push) Successful in 1m51s
Test / build (map[name:nightly]) (push) Successful in 2m4s
Release Please / Release-plz (push) Failing after 20s

This commit is contained in:
Paul Campbell 2024-12-15 20:07:34 +00:00
parent b8f85bb5eb
commit 7af4dae96d
12 changed files with 36 additions and 34 deletions

View file

@ -5,11 +5,11 @@ use color_eyre::Result;
use crate::FullCtx; use crate::FullCtx;
pub(crate) trait Execute { pub(crate) trait Execute {
async fn execute(self, ctx: &FullCtx) -> Result<()>; async fn execute(&self, ctx: &FullCtx) -> Result<()>;
} }
impl Execute for crate::Command { impl Execute for crate::Command {
async fn execute(self, ctx: &FullCtx) -> Result<()> { async fn execute(&self, ctx: &FullCtx) -> Result<()> {
match self { match self {
Self::Init => Err(eyre!("Config file already exists. Not overwriting it.")), Self::Init => Err(eyre!("Config file already exists. Not overwriting it.")),
Self::Check => crate::check::run(ctx).await, Self::Check => crate::check::run(ctx).await,

View file

@ -41,10 +41,10 @@ pub(crate) enum NextcloudCardCommand {
} }
impl Execute for 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 { match self {
Self::List { dump, stack_id } => { Self::List { dump, stack_id } => {
list(ctx, dump, NextcloudStackId::from(stack_id)).await list(ctx, *dump, NextcloudStackId::from(*stack_id)).await
} }
Self::Get { Self::Get {
dump, dump,
@ -53,9 +53,9 @@ impl Execute for NextcloudCardCommand {
} => { } => {
get( get(
ctx, ctx,
dump, *dump,
NextcloudStackId::from(stack_id), NextcloudStackId::from(*stack_id),
NextcloudCardId::from(card_id), NextcloudCardId::from(*card_id),
) )
.await .await
} }
@ -68,10 +68,10 @@ impl Execute for NextcloudCardCommand {
create( create(
ctx, ctx,
Create { Create {
dump, dump: *dump,
stack_id, stack_id: (*stack_id),
title, title: title.clone(),
description, description: description.clone(),
}, },
) )
.await .await
@ -85,10 +85,10 @@ impl Execute for NextcloudCardCommand {
add_label( add_label(
ctx, ctx,
AddLabel { AddLabel {
dump, dump: *dump,
stack_id: NextcloudStackId::from(stack_id), stack_id: NextcloudStackId::from(*stack_id),
card_id: NextcloudCardId::from(card_id), card_id: NextcloudCardId::from(*card_id),
label_id: NextcloudLabelId::from(label_id), label_id: NextcloudLabelId::from(*label_id),
}, },
) )
.await .await

View file

@ -13,11 +13,11 @@ pub(crate) enum NextcloudDeckCommand {
} }
impl Execute for 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 { match self {
Self::Get { dump } => { Self::Get { dump } => {
let api_result = ctx.deck_client().get_boards().await; let api_result = ctx.deck_client().get_boards().await;
if dump { if *dump {
p!(ctx.prt, "{}", api_result.text); p!(ctx.prt, "{}", api_result.text);
} else { } else {
let mut boards = api_result.result?; let mut boards = api_result.result?;

View file

@ -38,7 +38,7 @@ pub(crate) enum NextcloudCommand {
Card(NextcloudCardCommand), Card(NextcloudCardCommand),
} }
impl Execute for NextcloudCommand { impl Execute for NextcloudCommand {
async fn execute(self, ctx: &FullCtx) -> color_eyre::Result<()> { async fn execute(&self, ctx: &FullCtx) -> color_eyre::Result<()> {
match self { match self {
NextcloudCommand::Deck(cmd) => cmd.execute(ctx).await, NextcloudCommand::Deck(cmd) => cmd.execute(ctx).await,
NextcloudCommand::Stack(cmd) => cmd.execute(ctx).await, NextcloudCommand::Stack(cmd) => cmd.execute(ctx).await,

View file

@ -13,9 +13,9 @@ pub(crate) enum NextcloudStackCommand {
} }
impl Execute for 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 { match self {
Self::List { dump } => list(ctx, dump).await, Self::List { dump } => list(ctx, *dump).await,
} }
} }
} }

View file

@ -25,7 +25,7 @@ pub(crate) enum TrelloAttachmentCommand {
} }
impl Execute for TrelloAttachmentCommand { impl Execute for TrelloAttachmentCommand {
async fn execute(self, ctx: &FullCtx) -> Result<()> { async fn execute(&self, ctx: &FullCtx) -> Result<()> {
match self { match self {
Self::Get { Self::Get {
dump, dump,
@ -38,7 +38,7 @@ impl Execute for TrelloAttachmentCommand {
.trello_client() .trello_client()
.card_attachment(&trello_card_id, &trello_attachment_id) .card_attachment(&trello_card_id, &trello_attachment_id)
.await; .await;
if dump { if *dump {
p!(ctx.prt, "{}", api_result.text); p!(ctx.prt, "{}", api_result.text);
} else { } else {
let attachment = api_result.result?; let attachment = api_result.result?;
@ -55,7 +55,7 @@ impl Execute for TrelloAttachmentCommand {
let trello_attachment_id = TrelloAttachmentId::new(attachment_id); let trello_attachment_id = TrelloAttachmentId::new(attachment_id);
let file_name = ctx let file_name = ctx
.trello_client() .trello_client()
.save_attachment(&trello_card_id, &trello_attachment_id, file_name) .save_attachment(&trello_card_id, &trello_attachment_id, file_name.as_ref())
.await?; .await?;
p!(ctx.prt, "Wrote: {}", file_name.display()); p!(ctx.prt, "Wrote: {}", file_name.display());
Ok(()) Ok(())

View file

@ -17,14 +17,14 @@ pub(crate) enum TrelloBoardCommand {
} }
impl Execute for 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 { match self {
Self::Get { dump, board_id } => { Self::Get { dump, board_id } => {
let api_result = ctx let api_result = ctx
.trello_client() .trello_client()
.board(&TrelloBoardId::new(board_id)) .board(&TrelloBoardId::new(board_id))
.await; .await;
if dump { if *dump {
p!(ctx.prt, "{}", api_result.text); p!(ctx.prt, "{}", api_result.text);
} else { } else {
let mut lists = api_result.result?.lists; let mut lists = api_result.result?.lists;

View file

@ -17,11 +17,11 @@ pub(crate) enum TrelloCardCommand {
} }
impl Execute for TrelloCardCommand { impl Execute for TrelloCardCommand {
async fn execute(self, ctx: &FullCtx) -> Result<()> { async fn execute(&self, ctx: &FullCtx) -> Result<()> {
match self { match self {
Self::Get { dump, card_id } => { Self::Get { dump, card_id } => {
let api_result = ctx.trello_client().card(&TrelloCardId::new(card_id)).await; let api_result = ctx.trello_client().card(&TrelloCardId::new(card_id)).await;
if dump { if *dump {
p!(ctx.prt, "{}", api_result.text); p!(ctx.prt, "{}", api_result.text);
} else { } else {
let attachments = api_result.result?.attachments; let attachments = api_result.result?.attachments;

View file

@ -68,11 +68,13 @@ impl<'ctx> TrelloClient<'ctx> {
&self, &self,
card_id: &TrelloCardId, card_id: &TrelloCardId,
attachment_id: &TrelloAttachmentId, attachment_id: &TrelloAttachmentId,
file_name: Option<std::path::PathBuf>, file_name: Option<&PathBuf>,
) -> color_eyre::Result<PathBuf> { ) -> color_eyre::Result<PathBuf> {
let attachment = self.card_attachment(card_id, attachment_id).await.result?; let attachment = self.card_attachment(card_id, attachment_id).await.result?;
let url = attachment.url; let url = attachment.url;
let file_name = file_name.unwrap_or_else(|| attachment.file_name.into()); let file_name = file_name
.cloned()
.unwrap_or_else(|| PathBuf::from(attachment.file_name));
crate::e!(self.ctx.prt, "file_name: {}", file_name.display()); crate::e!(self.ctx.prt, "file_name: {}", file_name.display());
crate::e!(self.ctx.prt, "base: {}", self.ctx.fs.base().display()); crate::e!(self.ctx.prt, "base: {}", self.ctx.fs.base().display());
let file_name = self.ctx.fs.base().join(file_name); let file_name = self.ctx.fs.base().join(file_name);

View file

@ -13,11 +13,11 @@ pub(crate) enum TrelloMemberCommand {
} }
impl Execute for 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 { match self {
Self::Get { dump } => { Self::Get { dump } => {
let api_result = ctx.trello_client().boards().await; let api_result = ctx.trello_client().boards().await;
if dump { if *dump {
p!(ctx.prt, "{}", api_result.text); p!(ctx.prt, "{}", api_result.text);
} else { } else {
let mut boards = api_result.result?; let mut boards = api_result.result?;

View file

@ -47,7 +47,7 @@ pub(crate) enum TrelloCommand {
} }
impl Execute for 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 { match self {
Self::Member(cmd) => cmd.execute(ctx).await, Self::Member(cmd) => cmd.execute(ctx).await,
Self::Board(cmd) => cmd.execute(ctx).await, Self::Board(cmd) => cmd.execute(ctx).await,

View file

@ -17,14 +17,14 @@ pub(crate) enum TrelloStackCommand {
} }
impl Execute for TrelloStackCommand { impl Execute for TrelloStackCommand {
async fn execute(self, ctx: &FullCtx) -> Result<()> { async fn execute(&self, ctx: &FullCtx) -> Result<()> {
match self { match self {
Self::Get { dump, list_id } => { Self::Get { dump, list_id } => {
let api_result = ctx let api_result = ctx
.trello_client() .trello_client()
.list_cards(&TrelloListId::new(list_id)) .list_cards(&TrelloListId::new(list_id))
.await; .await;
if dump { if *dump {
p!(ctx.prt, "{}", api_result.text); p!(ctx.prt, "{}", api_result.text);
} else { } else {
let cards = api_result.result?; let cards = api_result.result?;