Skip to content

Commit

Permalink
Print some message before executing the clean job for better UX
Browse files Browse the repository at this point in the history
  • Loading branch information
rakivo committed Feb 23, 2025
1 parent 0374040 commit 132124c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/cr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<'a> CommandRunner<'a> {
cr.finish()
}

fn execute_command(&self, command: &Command, target: &str) -> io::Result<()> {
fn execute_command(&self, command: &Command, target: &str) -> io::Result::<()> {
if self.ran_any_edges.load(Ordering::Relaxed) {
_ = self.ran_any_edges.store(true, Ordering::Relaxed)
}
Expand Down Expand Up @@ -205,6 +205,14 @@ impl<'a> CommandRunner<'a> {
Ok(())
}

#[inline(always)]
fn execute_clean(&self) {
println!("[cleaning..]");
_ = self.execute_command(&self.clean(), CLEAN_TARGET).map(|_| {
self.executed_edges_curr_level.fetch_add(1, Ordering::Relaxed)
});
}

#[inline(always)]
fn clean(&self) -> &Command {
self.clean.get_or_init(|| {
Expand All @@ -214,9 +222,7 @@ impl<'a> CommandRunner<'a> {

fn run_phony(&self, edge: &'a Edge<'a>) {
if edge.target == CLEAN_TARGET {
_ = self.execute_command(&self.clean(), CLEAN_TARGET).map(|_| {
self.executed_edges_curr_level.fetch_add(1, Ordering::Relaxed)
});
self.execute_clean();
return
}

Expand Down Expand Up @@ -312,9 +318,7 @@ impl<'a> CommandRunner<'a> {
}

if edge.target == CLEAN_TARGET {
_ = self.execute_command(&self.clean(), CLEAN_TARGET).map(|_| {
self.executed_edges_curr_level.fetch_add(1, Ordering::Relaxed)
});
self.execute_clean();
return ExecutorFlow::Ok
}

Expand Down
10 changes: 4 additions & 6 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,12 @@ impl Compiled<'_> {
} files
});


if fs::exists::<&Path>(Db::RUSH_FILE_NAME.as_ref()).unwrap_or(false) {
targets.push(Db::RUSH_FILE_NAME)
}

let count = targets.len().to_string();

let (command, description) = if flags.verbose() {
let targets_str = targets.join(" ");
let command = format!("rm -f {targets_str}");
Expand All @@ -485,16 +486,13 @@ impl Compiled<'_> {
description.push_str("]\n");
}
description.push_str("[cleaned ");
description.push_str(&targets.len().to_string());
description.push_str(&count);
description.push_str(" files]");
(command, description)
} else {
let targets_str = targets.join(" ");
let command = format!("rm -f {targets_str}");
let description = format!{
"[cleaned {count} files]",
count = targets.len()
};
let description = format!("[cleaned {count} files]");
(command, description)
};

Expand Down

0 comments on commit 132124c

Please sign in to comment.