From 536613852f109c8466cd93a8686cb3a705885c21 Mon Sep 17 00:00:00 2001 From: Matt Green Date: Thu, 13 Oct 2016 20:21:29 -0400 Subject: [PATCH] Enhance debug output; rename option back to debug --- src/main.rs | 15 +++++++-------- src/notification_filter.rs | 13 +++++++++++++ src/runner.rs | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1fe232b..8800696 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,10 +48,10 @@ fn get_args<'a>() -> ArgMatches<'a> { .help("Restart the process if it's still running") .short("r") .long("restart")) - .arg(Arg::with_name("verbose") - .help("Prints diagnostic messages") - .short("v") - .long("verbose")) + .arg(Arg::with_name("debug") + .help("Print debugging messages to stderr") + .short("d") + .long("debug")) .arg(Arg::with_name("filter") .help("Ignore all modifications except those matching the pattern") .short("f") @@ -74,10 +74,10 @@ fn get_args<'a>() -> ArgMatches<'a> { .get_matches() } -fn init_logger(verbose: bool) { +fn init_logger(debug: bool) { let mut log_builder = env_logger::LogBuilder::new(); let mut level = log::LogLevelFilter::Warn; - if verbose { + if debug { level = log::LogLevelFilter::Debug; } @@ -90,7 +90,7 @@ fn init_logger(verbose: bool) { fn main() { let args = get_args(); - init_logger(args.is_present("verbose")); + init_logger(args.is_present("debug")); let cwd = env::current_dir() .expect("unable to get cwd") @@ -167,7 +167,6 @@ fn wait(rx: &Receiver, filter: &NotificationFilter) -> Result bool { let path_as_str = path.to_str().unwrap(); + if let Ok(metadata) = path.metadata() { + if metadata.is_dir() { + debug!("Ignoring {:?}: is a directory", path); + return true; + } + } + for pattern in &self.ignores { if pattern.matches(path_as_str) { + debug!("Ignoring {:?}: matched ignore filter", path); return true; } } @@ -95,10 +103,15 @@ impl NotificationFilter { if let Some(ref ignore_file) = self.ignore_file { if ignore_file.is_excluded(path) { + debug!("Ignoring {:?}: matched gitignore file", path); return true; } } + if self.filters.len() > 0 { + debug!("Ignoring {:?}: did not match any given filters", path); + } + self.filters.len() > 0 } } diff --git a/src/runner.rs b/src/runner.rs index 783a1bc..ad85fc2 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -53,9 +53,11 @@ impl Runner { pub fn run_command(&mut self, cmd: &str) { if let Some(ref mut child) = self.process { if self.restart { + debug!("Killing child process (pid: {})", child.id()); let _ = child.kill(); } + debug!("Waiting for child process (pid: {})", child.id()); let _ = child.wait(); }