hyperlane_cli/watch/
fn.rs1use crate::*;
2
3async fn is_cargo_watch_installed() -> bool {
9 Command::new("cargo-watch")
10 .arg("--version")
11 .stdout(Stdio::null())
12 .stderr(Stdio::null())
13 .status()
14 .await
15 .is_ok_and(|status: ExitStatus| status.success())
16}
17
18async fn install_cargo_watch() -> Result<(), std::io::Error> {
24 println!("cargo-watch not found, installing...");
25 let mut cmd: Command = Command::new("cargo");
26 cmd.arg("install").arg("cargo-watch");
27 cmd.stdout(Stdio::inherit()).stderr(Stdio::inherit());
28 let status: ExitStatus = cmd.status().await?;
29 if !status.success() {
30 return Err(std::io::Error::other("failed to install cargo-watch"));
31 }
32 Ok(())
33}
34
35pub async fn execute_watch() -> Result<(), std::io::Error> {
41 if !is_cargo_watch_installed().await {
42 install_cargo_watch().await?;
43 }
44 let mut cmd: Command = Command::new("cargo-watch");
45 cmd.arg("--clear")
46 .arg("--skip-local-deps")
47 .arg("-q")
48 .arg("-x")
49 .arg("run");
50 cmd.stdout(Stdio::inherit()).stderr(Stdio::inherit());
51 let status: ExitStatus = cmd.status().await?;
52 if !status.success() {
53 return Err(std::io::Error::other("cargo-watch failed"));
54 }
55 Ok(())
56}