From 685b9f9d329a5773b211035db156fa8220163a2c Mon Sep 17 00:00:00 2001 From: GideonBear <87426140+GideonBear@users.noreply.github.com> Date: Sat, 3 May 2025 17:01:03 +0200 Subject: [PATCH 1/3] Improve Runner::execute --- src/main.rs | 2 +- src/runner.rs | 20 +++++++++++++++++--- src/steps/generic.rs | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5f78a5ac8..a482bdc46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -502,7 +502,7 @@ fn run() -> Result<()> { runner.execute(Step::JetbrainsWebstorm, "JetBrains WebStorm plugins", || { generic::run_jetbrains_webstorm(&ctx) })?; - runner.execute(Step::Yazi, "Yazi packages", || generic::run_yazi(&ctx))?; + runner.execute_2(Step::Yazi, "Yazi packages", generic::run_yazi)?; if should_run_powershell { runner.execute(Step::Powershell, "Powershell Modules Update", || { diff --git a/src/runner.rs b/src/runner.rs index af26c7253..0d248ded0 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -2,7 +2,7 @@ use crate::ctrlc; use crate::error::{DryRun, SkipStep}; use crate::execution_context::ExecutionContext; use crate::report::{Report, StepResult}; -use crate::terminal::print_error; +use crate::terminal::{print_error, print_separator}; use crate::{config::Step, terminal::should_retry}; use color_eyre::eyre::Result; use std::borrow::Cow; @@ -26,6 +26,14 @@ impl<'a> Runner<'a> { where F: Fn() -> Result<()>, M: Into> + Debug, + { + todo!("This function will be removed and `execute_2` will be renamed to `execute`") + } + + pub fn execute_2(&mut self, step: Step, key: M, func: F) -> Result<()> + where + F: Fn(&ExecutionContext, &dyn Fn()) -> Result<()>, + M: Into> + Debug, { if !self.ctx.config().should_run(step) { return Ok(()); @@ -34,12 +42,14 @@ impl<'a> Runner<'a> { let key = key.into(); debug!("Step {:?}", key); - // alter the `func` to put it in a span + let confirm_run = || Runner::confirm_run(&key); + + // Alter the `func` to put it in a span, and add `ctx` and `confirm_run` let func = || { let span = tracing::span!(parent: tracing::Span::none(), tracing::Level::TRACE, "step", step = ?step, key = %key); let _guard = span.enter(); - func() + func(self.ctx, &confirm_run) }; loop { @@ -89,6 +99,10 @@ impl<'a> Runner<'a> { Ok(()) } + fn confirm_run(key: &str) { + print_separator(key); + } + pub fn report(&self) -> &Report { &self.report } diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 4e7e97964..46834b76d 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -1616,10 +1616,10 @@ pub fn run_jetbrains_webstorm(ctx: &ExecutionContext) -> Result<()> { run_jetbrains_ide(ctx, require("webstorm")?, "WebStorm") } -pub fn run_yazi(ctx: &ExecutionContext) -> Result<()> { +pub fn run_yazi(ctx: &ExecutionContext, confirm_run: &dyn Fn()) -> Result<()> { let ya = require("ya")?; - print_separator("Yazi packages"); + confirm_run(); ctx.run_type().execute(ya).args(["pack", "-u"]).status_checked() } From 154c24eb895d0ab1dfd7439968cc04e8312510a3 Mon Sep 17 00:00:00 2001 From: GideonBear <87426140+GideonBear@users.noreply.github.com> Date: Sat, 3 May 2025 17:11:19 +0200 Subject: [PATCH 2/3] Make Runner::confirm_run take &self --- src/runner.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index 0d248ded0..215ec6bd7 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -42,7 +42,7 @@ impl<'a> Runner<'a> { let key = key.into(); debug!("Step {:?}", key); - let confirm_run = || Runner::confirm_run(&key); + let confirm_run = || self.confirm_run(&key); // Alter the `func` to put it in a span, and add `ctx` and `confirm_run` let func = || { @@ -99,7 +99,7 @@ impl<'a> Runner<'a> { Ok(()) } - fn confirm_run(key: &str) { + fn confirm_run(&self, key: &str) { print_separator(key); } From bd35423da5c8ccb7f7bb831cc914103d6f741305 Mon Sep 17 00:00:00 2001 From: GideonBear <87426140+GideonBear@users.noreply.github.com> Date: Mon, 29 Sep 2025 17:16:49 +0200 Subject: [PATCH 3/3] Format --- src/runner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.rs b/src/runner.rs index c37a394b7..c27c48ce9 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -7,8 +7,8 @@ use tracing::debug; use crate::ctrlc; use crate::error::{DryRun, MissingSudo, SkipStep}; use crate::execution_context::ExecutionContext; -use crate::step::Step; use crate::report::{Report, StepResult}; +use crate::step::Step; use crate::terminal::{print_error, print_separator, print_warning, should_retry}; pub enum StepResult {