Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use tracing::debug;
use crate::ctrlc;
use crate::error::{DryRun, MissingSudo, SkipStep};
use crate::execution_context::ExecutionContext;
use crate::report::{Report, StepResult};
use crate::step::Step;
use crate::terminal::{print_error, print_warning, should_retry};
use crate::terminal::{print_error, print_separator, print_warning, should_retry};

pub enum StepResult {
Success,
Expand Down Expand Up @@ -53,6 +54,14 @@ impl<'a> Runner<'a> {
where
K: Into<Cow<'a, str>> + Debug,
F: Fn() -> Result<()>,
{
todo!("This function will be removed and `execute_2` will be renamed to `execute`")
}

pub fn execute_2<F, M>(&mut self, step: Step, key: M, func: F) -> Result<()>
where
F: Fn(&ExecutionContext, &dyn Fn()) -> Result<()>,
M: Into<Cow<'a, str>> + Debug,
{
if !self.ctx.config().should_run(step) {
return Ok(());
Expand All @@ -61,12 +70,14 @@ impl<'a> Runner<'a> {
let key: Cow<'a, str> = key.into();
debug!("Step {:?}", key);

// alter the `func` to put it in a span
let confirm_run = || self.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 {
Expand Down Expand Up @@ -121,6 +132,10 @@ impl<'a> Runner<'a> {
Ok(())
}

fn confirm_run(&self, key: &str) {
print_separator(key);
}

pub fn report(&self) -> &Report<'_> {
&self.report
}
Expand Down
2 changes: 1 addition & 1 deletion src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl Step {
runner.execute(*self, "yadm", || unix::run_yadm(ctx))?
}
Yarn => runner.execute(*self, "yarn", || node::run_yarn_upgrade(ctx))?,
Yazi => runner.execute(*self, "Yazi packages", || generic::run_yazi(ctx))?,
Yazi => runner.execute_2(*self, "Yazi packages", generic::run_yazi)?,
Zigup => runner.execute(*self, "zigup", || generic::run_zigup(ctx))?,
Zvm => runner.execute(*self, "ZVM", || generic::run_zvm(ctx))?,
}
Expand Down
4 changes: 2 additions & 2 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1736,10 +1736,10 @@ pub fn run_jetbrains_webstorm(ctx: &ExecutionContext) -> Result<()> {
run_jetbrains_ide(ctx, require_one(["webstorm", "webstorm-eap"])?, "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.execute(ya).args(["pkg", "upgrade"]).status_checked()
}
Loading