refactor: pass context by reference
Some checks failed
Test / build (map[name:stable]) (push) Successful in 2m9s
Test / build (map[name:nightly]) (push) Successful in 2m5s
Release Please / Release-plz (push) Failing after 13s

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

View file

@ -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...");

View file

@ -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,

View file

@ -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

View file

@ -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
}

View file

@ -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<String>,
}
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);

View file

@ -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;

View file

@ -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,

View file

@ -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)

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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,

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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,

View file

@ -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

View file

@ -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");

View file

@ -104,7 +104,7 @@ async fn save(
attachment_id: attachment_id.into(),
file_name: None, // Case?
}))
.execute(ctx)
.execute(&ctx)
.await
.expect("execute");

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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");