refactor: Execute::execute passes itself by ref
This commit is contained in:
parent
b8f85bb5eb
commit
7af4dae96d
12 changed files with 36 additions and 34 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -53,9 +53,9 @@ impl Execute for NextcloudCardCommand {
|
|||
} => {
|
||||
get(
|
||||
ctx,
|
||||
dump,
|
||||
NextcloudStackId::from(stack_id),
|
||||
NextcloudCardId::from(card_id),
|
||||
*dump,
|
||||
NextcloudStackId::from(*stack_id),
|
||||
NextcloudCardId::from(*card_id),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -68,10 +68,10 @@ impl Execute for NextcloudCardCommand {
|
|||
create(
|
||||
ctx,
|
||||
Create {
|
||||
dump,
|
||||
stack_id,
|
||||
title,
|
||||
description,
|
||||
dump: *dump,
|
||||
stack_id: (*stack_id),
|
||||
title: title.clone(),
|
||||
description: description.clone(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
@ -85,10 +85,10 @@ impl Execute for NextcloudCardCommand {
|
|||
add_label(
|
||||
ctx,
|
||||
AddLabel {
|
||||
dump,
|
||||
stack_id: NextcloudStackId::from(stack_id),
|
||||
card_id: NextcloudCardId::from(card_id),
|
||||
label_id: NextcloudLabelId::from(label_id),
|
||||
dump: *dump,
|
||||
stack_id: NextcloudStackId::from(*stack_id),
|
||||
card_id: NextcloudCardId::from(*card_id),
|
||||
label_id: NextcloudLabelId::from(*label_id),
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -13,11 +13,11 @@ 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;
|
||||
if dump {
|
||||
if *dump {
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let mut boards = api_result.result?;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -13,9 +13,9 @@ 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,
|
||||
Self::List { dump } => list(ctx, *dump).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -38,7 +38,7 @@ impl Execute for TrelloAttachmentCommand {
|
|||
.trello_client()
|
||||
.card_attachment(&trello_card_id, &trello_attachment_id)
|
||||
.await;
|
||||
if dump {
|
||||
if *dump {
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let attachment = api_result.result?;
|
||||
|
@ -55,7 +55,7 @@ impl Execute for TrelloAttachmentCommand {
|
|||
let trello_attachment_id = TrelloAttachmentId::new(attachment_id);
|
||||
let file_name = ctx
|
||||
.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?;
|
||||
p!(ctx.prt, "Wrote: {}", file_name.display());
|
||||
Ok(())
|
||||
|
|
|
@ -17,14 +17,14 @@ 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
|
||||
.trello_client()
|
||||
.board(&TrelloBoardId::new(board_id))
|
||||
.await;
|
||||
if dump {
|
||||
if *dump {
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let mut lists = api_result.result?.lists;
|
||||
|
|
|
@ -17,11 +17,11 @@ 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;
|
||||
if dump {
|
||||
if *dump {
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let attachments = api_result.result?.attachments;
|
||||
|
|
|
@ -68,11 +68,13 @@ impl<'ctx> TrelloClient<'ctx> {
|
|||
&self,
|
||||
card_id: &TrelloCardId,
|
||||
attachment_id: &TrelloAttachmentId,
|
||||
file_name: Option<std::path::PathBuf>,
|
||||
file_name: Option<&PathBuf>,
|
||||
) -> color_eyre::Result<PathBuf> {
|
||||
let attachment = self.card_attachment(card_id, attachment_id).await.result?;
|
||||
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, "base: {}", self.ctx.fs.base().display());
|
||||
let file_name = self.ctx.fs.base().join(file_name);
|
||||
|
|
|
@ -13,11 +13,11 @@ 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;
|
||||
if dump {
|
||||
if *dump {
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let mut boards = api_result.result?;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -17,14 +17,14 @@ 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
|
||||
.trello_client()
|
||||
.list_cards(&TrelloListId::new(list_id))
|
||||
.await;
|
||||
if dump {
|
||||
if *dump {
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let cards = api_result.result?;
|
||||
|
|
Loading…
Reference in a new issue