mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
Set $WATCHEXEC_UPDATED_PATH to first changed path in child process;
closes #11
This commit is contained in:
parent
249e5a84e4
commit
a75dd49114
10
src/main.rs
10
src/main.rs
@ -176,7 +176,7 @@ fn main() {
|
|||||||
let mut runner = Runner::new(args.is_present("restart"), args.is_present("clear"));
|
let mut runner = Runner::new(args.is_present("restart"), args.is_present("clear"));
|
||||||
|
|
||||||
if args.is_present("run-initially") {
|
if args.is_present("run-initially") {
|
||||||
runner.run_command(&cmd);
|
runner.run_command(&cmd, vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -184,7 +184,13 @@ fn main() {
|
|||||||
|
|
||||||
debug!("{:?}: {:?}", e.op, e.path);
|
debug!("{:?}: {:?}", e.op, e.path);
|
||||||
|
|
||||||
runner.run_command(&cmd);
|
// TODO: update wait to return all paths
|
||||||
|
let updated: Vec<&str> = e.path
|
||||||
|
.iter()
|
||||||
|
.map(|p| p.to_str().unwrap())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
runner.run_command(&cmd, updated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,24 +26,30 @@ impl Runner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
fn invoke(&self, cmd: &str) -> Option<Child> {
|
fn invoke(&self, cmd: &str, updated_paths: Vec<&str>) -> Option<Child> {
|
||||||
Command::new("cmd.exe")
|
let mut command = Command::new("cmd.exe");
|
||||||
.arg("/C")
|
command.arg("/C").arg(cmd);
|
||||||
.arg(cmd)
|
|
||||||
.spawn()
|
if updated_files.len() > 0 {
|
||||||
.ok()
|
command.env("WATCHEXEC_UPDATED_PATH", updated_paths[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
command.spawn().ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
fn invoke(&self, cmd: &str) -> Option<Child> {
|
fn invoke(&self, cmd: &str, updated_paths: Vec<&str>) -> Option<Child> {
|
||||||
Command::new("sh")
|
let mut command = Command::new("sh");
|
||||||
.arg("-c")
|
command.arg("-c").arg(cmd);
|
||||||
.arg(cmd)
|
|
||||||
.spawn()
|
if updated_paths.len() > 0 {
|
||||||
.ok()
|
command.env("WATCHEXEC_UPDATED_PATH", updated_paths[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_command(&mut self, cmd: &str) {
|
command.spawn().ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_command(&mut self, cmd: &str, updated_paths: Vec<&str>) {
|
||||||
if let Some(ref mut child) = self.process {
|
if let Some(ref mut child) = self.process {
|
||||||
if self.restart {
|
if self.restart {
|
||||||
debug!("Killing child process (pid: {})", child.id());
|
debug!("Killing child process (pid: {})", child.id());
|
||||||
@ -60,6 +66,6 @@ impl Runner {
|
|||||||
|
|
||||||
debug!("Executing: {}", cmd);
|
debug!("Executing: {}", cmd);
|
||||||
|
|
||||||
self.process = self.invoke(cmd);
|
self.process = self.invoke(cmd, updated_paths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user