Skip to content

Commit

Permalink
clippy && fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
deniz committed Jan 31, 2024
1 parent 8df89f8 commit a2c4e05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/hot_reload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl<'a> DevSession<'a> {

#[allow(unused_assignments)]
#[allow(clippy::too_many_lines)]
#[allow(clippy::await_holding_lock)]
async fn handle_commands(
mut self,
mut rx: mpsc::Receiver<Command>,
Expand Down
32 changes: 17 additions & 15 deletions src/interop/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use console::style;
use indicatif::{ProgressBar, ProgressStyle};
use tokio::{io::AsyncBufReadExt, process::Command};

use crate::{app::App, model::{HookEvent, HookFailBehavior}};
use crate::{
app::App,
model::{HookEvent, HookFailBehavior},
};

pub struct HooksAPI<'a>(pub &'a App);

Expand Down Expand Up @@ -45,7 +48,8 @@ impl<'a> HooksAPI<'a> {
continue;
}

let spinner = self.0
let spinner = self
.0
.multi_progress
.add(
ProgressBar::new_spinner().with_style(ProgressStyle::with_template(
Expand All @@ -54,10 +58,11 @@ impl<'a> HooksAPI<'a> {
);

spinner.enable_steady_tick(Duration::from_millis(200));
spinner.set_prefix(format!(
"Running hook {}",
style(filename.clone()).blue()
));
spinner.set_prefix(format!("Running hook {}", style(filename.clone()).blue()));

if hook.show_output {
self.0.log_dev(format!("Running {filename}"));
}

let mut cmd = Command::new(path);
cmd.kill_on_drop(true)
Expand All @@ -68,8 +73,7 @@ impl<'a> HooksAPI<'a> {
cmd.env(k, v);
}

let mut child = cmd.spawn()
.context(format!("Spawning hook {filename}"))?;
let mut child = cmd.spawn().context(format!("Spawning hook {filename}"))?;

let stdout = child.stdout.take().unwrap();
let mut lines = tokio::io::BufReader::new(stdout).lines();
Expand All @@ -78,23 +82,21 @@ impl<'a> HooksAPI<'a> {
spinner.set_message(line.clone());
if hook.show_output {
self.0.multi_progress.suspend(|| {
println!(
"{}{}",
style("| ").bold(),
line.trim()
);
println!("{}{}", style("| ").bold(), line.trim());
});
}
}

let status = child.wait().await
let status = child
.wait()
.await
.context(format!("waiting hook {filename}"))?;
spinner.finish_and_clear();
if status.success() {
self.0.success(format!("Hook {filename}"));
} else {
match hook.onfail {
HookFailBehavior::Ignore => {},
HookFailBehavior::Ignore => {}
HookFailBehavior::Warn => self.0.warn(format!("Hook {filename} failed")),
HookFailBehavior::Error => bail!("Hook {filename} failed"),
}
Expand Down

0 comments on commit a2c4e05

Please sign in to comment.