From 14475625450a44cf249ea38e27f71004664abdae Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Mon, 19 Sep 2022 15:23:38 +0530 Subject: [PATCH] [sniff] Change debug -> info in some places Signed-off-by: Shinyzenith --- sniff.1.scd | 31 ------------------------------- sniff.5.scd | 42 ------------------------------------------ src/sniff.rs | 20 ++++++++++++-------- 3 files changed, 12 insertions(+), 81 deletions(-) delete mode 100644 sniff.1.scd delete mode 100644 sniff.5.scd diff --git a/sniff.1.scd b/sniff.1.scd deleted file mode 100644 index 7c7a474..0000000 --- a/sniff.1.scd +++ /dev/null @@ -1,31 +0,0 @@ -sniff(1) "github.com/shinyzenith/sniff" "General Commands Manual" - -# NAME - -sniff - Executes build commands in response to file modifications - -# SYNOPSIS - -*sniff* [_flags_] - -# DESCRIPTION - -*sniff* is a simple tool written in rust to automatically run build commands -by watching the filesystem. - -# OPTIONS - -*-h* - Print a help message and exit. - -*-d* - Enable debug mode. - -# AUTHORS - -Maintained by Shinyzenith . -For more information about development, see . - -# SEE ALSO - -*sniff*(5) diff --git a/sniff.5.scd b/sniff.5.scd deleted file mode 100644 index 7484238..0000000 --- a/sniff.5.scd +++ /dev/null @@ -1,42 +0,0 @@ -sniff(5) "github.com/shinyzenith/sniff" "File Formats Manual" - -# NAME - -sniff - Executes build commands in response to file modifications - -# CONFIG FILE - -Sniff uses the JSON file format. Configuration files should always be named *sniff.json*. - -- A global config can be defined in *~/.config/sniff/sniff.json*. Sniff attempts to look in your *$XDG_CONFIG_HOME*, failing which it defaults to *~/.config*. -- A local config overrides the global one. Local configs should be placed in the root of the project. - -# SYNTAX - - -All JSON keys apart from the following are treated as regular expressions to -check for file changes: - - _sniff_ignore_dir_ (Make sniff ignore directories.) - - _sniff_ignore_file_ (Make sniff ignore files.) - - _sniff_cooldown_ (State the cooldown between consecutive build commands.) - -# EXAMPLE - -``` -{ - ".*.rs": ["cargo build --release"], - ".*.zig": ["zig test .", "zig build"], - "sniff_ignore_dir": ["target"], - "sniff_ignore_file": ["test.rs"], - "sniff_cooldown": 650 -} -``` - -# AUTHORS - -Maintained by Shinyzenith . -For more information about development, see . - -# SEE ALSO - -*sniff*(1) diff --git a/src/sniff.rs b/src/sniff.rs index 564f59a..814de8f 100644 --- a/src/sniff.rs +++ b/src/sniff.rs @@ -21,7 +21,7 @@ struct Ignore { fn main() { let mut last_run: Instant = Instant::now(); - env::set_var("RUST_LOG", "sniff=warn"); + env::set_var("RUST_LOG", "sniff=info"); let mut args = args(); if let Some(arg) = args.nth(1) { match arg.as_str() { @@ -87,7 +87,9 @@ fn fetch_sniff_config_file() -> String { Path::new(&val).join("sniff/sniff.json") } Err(_) => { - log::error!("XDG_CONFIG_HOME has not been set."); + log::error!( + "XDG_CONFIG_HOME has not been set. Falling back to ~/.config/sniff/sniff.json" + ); Path::new("~/.config/sniff/sniff.json").to_path_buf() } }; @@ -107,7 +109,7 @@ fn run_system_command(command: &str) { log::error!("Failed to execute {}", command); log::error!("Error, {}", e); } else { - log::debug!("Ran: {:#?}", command); + log::info!("Ran: {:#?}", command); } } @@ -117,6 +119,12 @@ fn check_and_run( ignore_list: Ignore, last_run: &mut Instant, ) { + // Cooldown check. + if Instant::now().duration_since(*last_run).as_millis() < ignore_list.sniff_cooldown { + log::debug!("In cooldown."); + return; + } + // First the file check. for ignore_file in ignore_list.sniff_ignore_file { if ignore_file[..] == file_name[file_name.rfind('/').unwrap() + 1..] { @@ -136,11 +144,6 @@ fn check_and_run( } } - // Cooldown check. - if Instant::now().duration_since(*last_run).as_millis() < ignore_list.sniff_cooldown { - log::debug!("In cooldown."); - return; - } *last_run = Instant::now(); match json { @@ -157,6 +160,7 @@ fn check_and_run( for command in arr { match command { serde_json::Value::String(command) => { + log::info!("Running build scripts for: {:#?}", file_name); run_system_command(command); } _ => {