From 68209baa77000d980acfd9a362e5b3aa28ce922d Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Tue, 13 Jul 2021 03:32:52 +0100 Subject: [PATCH] Only watch if 'watch' passed as argument --- build_src/main.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/build_src/main.rs b/build_src/main.rs index a1b260c..f04ca43 100644 --- a/build_src/main.rs +++ b/build_src/main.rs @@ -45,21 +45,24 @@ fn build() { } fn main() { - println!("Watching...\n"); - - use notify::*; - - let (tx, rx) = std::sync::mpsc::channel(); - - let mut watcher = watcher(tx, Duration::from_millis(100)).unwrap(); build(); - watcher.watch("./src", RecursiveMode::Recursive).unwrap(); + if matches!(std::env::args().nth(1).as_deref(), Some("watch")) { + use notify::*; - loop { - match rx.recv() { - Ok(_) => build(), - Err(_) => break, + let (tx, rx) = std::sync::mpsc::channel(); + + let mut watcher = watcher(tx, Duration::from_millis(100)).unwrap(); + watcher.watch("./src", RecursiveMode::Recursive).unwrap(); + + println!(); + log_info("Watching…\n"); + + loop { + match rx.recv() { + Ok(_) => build(), + Err(_) => break, + } } } }