mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
Add -1 option for integration testing, closes #35
This commit is contained in:
parent
0d5de7c4da
commit
b2b0a60ca5
@ -14,6 +14,7 @@ pub struct Args {
|
|||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub run_initially: bool,
|
pub run_initially: bool,
|
||||||
pub no_vcs_ignore: bool,
|
pub no_vcs_ignore: bool,
|
||||||
|
pub once: bool,
|
||||||
pub poll: bool,
|
pub poll: bool,
|
||||||
pub poll_interval: u32,
|
pub poll_interval: u32,
|
||||||
}
|
}
|
||||||
@ -86,6 +87,9 @@ pub fn get_args() -> Args {
|
|||||||
.help("Send SIGKILL to child processes")
|
.help("Send SIGKILL to child processes")
|
||||||
.short("k")
|
.short("k")
|
||||||
.long("kill"))
|
.long("kill"))
|
||||||
|
.arg(Arg::with_name("once")
|
||||||
|
.short("1")
|
||||||
|
.hidden(true))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let cmd = values_t!(args.values_of("command"), String).unwrap().join(" ");
|
let cmd = values_t!(args.values_of("command"), String).unwrap().join(" ");
|
||||||
@ -125,6 +129,7 @@ pub fn get_args() -> Args {
|
|||||||
debug: args.is_present("debug"),
|
debug: args.is_present("debug"),
|
||||||
run_initially: !args.is_present("postpone"),
|
run_initially: !args.is_present("postpone"),
|
||||||
no_vcs_ignore: args.is_present("no-vcs-ignore"),
|
no_vcs_ignore: args.is_present("no-vcs-ignore"),
|
||||||
|
once: args.is_present("once"),
|
||||||
poll: args.occurrences_of("poll") > 0,
|
poll: args.occurrences_of("poll") > 0,
|
||||||
poll_interval: poll_interval,
|
poll_interval: poll_interval,
|
||||||
}
|
}
|
||||||
|
48
src/main.rs
48
src/main.rs
@ -108,7 +108,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start child process initially, if necessary
|
// Start child process initially, if necessary
|
||||||
if args.run_initially {
|
if args.run_initially && !args.once {
|
||||||
if args.clear_screen {
|
if args.clear_screen {
|
||||||
cli::clear_screen();
|
cli::clear_screen();
|
||||||
}
|
}
|
||||||
@ -119,29 +119,13 @@ fn main() {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
debug!("Waiting for filesystem activity");
|
debug!("Waiting for filesystem activity");
|
||||||
let paths = wait(&rx, &filter);
|
let paths = wait_fs(&rx, &filter);
|
||||||
if let Some(path) = paths.get(0) {
|
if let Some(path) = paths.get(0) {
|
||||||
debug!("Path updated: {:?}", path);
|
debug!("Path updated: {:?}", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for current child process to exit
|
// Wait for current child process to exit
|
||||||
{
|
wait_process(&child_process, kill, args.restart);
|
||||||
let guard = child_process.read().unwrap();
|
|
||||||
|
|
||||||
if let Some(ref child) = *guard {
|
|
||||||
if args.restart {
|
|
||||||
debug!("Stopping child process");
|
|
||||||
if kill {
|
|
||||||
child.kill();
|
|
||||||
} else {
|
|
||||||
child.terminate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("Waiting for process to exit...");
|
|
||||||
child.wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch child process
|
// Launch child process
|
||||||
if args.clear_screen {
|
if args.clear_screen {
|
||||||
@ -153,10 +137,16 @@ fn main() {
|
|||||||
let mut guard = child_process.write().unwrap();
|
let mut guard = child_process.write().unwrap();
|
||||||
*guard = Some(process::spawn(&args.cmd, paths));
|
*guard = Some(process::spawn(&args.cmd, paths));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle once option for integration testing
|
||||||
|
if args.once {
|
||||||
|
wait_process(&child_process, kill, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait(rx: &Receiver<Event>, filter: &NotificationFilter) -> Vec<PathBuf> {
|
fn wait_fs(rx: &Receiver<Event>, filter: &NotificationFilter) -> Vec<PathBuf> {
|
||||||
let mut paths = vec![];
|
let mut paths = vec![];
|
||||||
let mut cache = HashMap::new();
|
let mut cache = HashMap::new();
|
||||||
|
|
||||||
@ -199,3 +189,21 @@ fn wait(rx: &Receiver<Event>, filter: &NotificationFilter) -> Vec<PathBuf> {
|
|||||||
|
|
||||||
paths
|
paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn wait_process(process: &RwLock<Option<Process>>, kill: bool, restart: bool) {
|
||||||
|
let guard = process.read().unwrap();
|
||||||
|
|
||||||
|
if let Some(ref child) = *guard {
|
||||||
|
if restart {
|
||||||
|
debug!("Stopping child process");
|
||||||
|
if kill {
|
||||||
|
child.kill();
|
||||||
|
} else {
|
||||||
|
child.terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("Waiting for process to exit...");
|
||||||
|
child.wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user