From 48bcf237af1e3bd67df672eaac0c80a9a4a01a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Fri, 11 Aug 2023 21:28:21 +1200 Subject: [PATCH] wip --- check-hashes.jaq | 15 +++++++++++++++ crates/cli/src/args.rs | 20 +++++++++++++++++--- crates/cli/src/filterer/progs.rs | 9 ++++----- crates/cli/src/lib.rs | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 check-hashes.jaq diff --git a/check-hashes.jaq b/check-hashes.jaq new file mode 100644 index 0000000..534fbfe --- /dev/null +++ b/check-hashes.jaq @@ -0,0 +1,15 @@ +# vim: ft=jq + +def has_changed: + . as $file | + file_hash | + { prev: kv_fetch($file), cur: (. | kv_store($file)) } | + .prev != .cur +; + +if any(.tags[]; .kind == "path") then + any( + .tags[] | select((.kind == "path") and (.filetype == "file")); + .absolute | has_changed + ) +else true end diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 9ca4b9a..01fc84d 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -9,6 +9,8 @@ use clap::{ builder::TypedValueParser, error::ErrorKind, Arg, ArgAction, Command, CommandFactory, Parser, ValueEnum, ValueHint, }; +use miette::{IntoDiagnostic, Result}; +use tokio::{fs::File, io::AsyncReadExt}; use watchexec::paths::PATH_SEPARATOR; use watchexec_signals::Signal; @@ -1153,8 +1155,8 @@ fn expand_args_up_to_doubledash() -> Result, std::io::Error> { } #[inline] -pub fn get_args() -> Args { - use tracing::{debug, warn}; +pub async fn get_args() -> Result { + use tracing::{debug, trace, warn}; if std::env::var("RUST_LOG").is_ok() { warn!("⚠ RUST_LOG environment variable set, logging options have no effect"); @@ -1224,6 +1226,18 @@ pub fn get_args() -> Args { .exit(); } + for (n, prog) in args.filter_programs.iter_mut().enumerate() { + if let Some(progpath) = prog.strip_prefix('@') { + trace!(?n, path=?progpath, "reading filter program from file"); + let mut progfile = File::open(&progpath).await.into_diagnostic()?; + let mut buf = + String::with_capacity(progfile.metadata().await.into_diagnostic()?.len() as _); + let bytes_read = progfile.read_to_string(&mut buf).await.into_diagnostic()?; + debug!(?n, path=?progpath, %bytes_read, "read filter program from file"); + *prog = buf; + } + } + debug!(?args, "got arguments"); - args + Ok(args) } diff --git a/crates/cli/src/filterer/progs.rs b/crates/cli/src/filterer/progs.rs index b305ca6..bb25dd2 100644 --- a/crates/cli/src/filterer/progs.rs +++ b/crates/cli/src/filterer/progs.rs @@ -67,7 +67,9 @@ impl FilterProgs { pub fn new(args: &Args) -> miette::Result { let n_filters = args.filter_programs.len(); let progs = args.filter_programs.clone(); - warn!("EXPERIMENTAL: filter programs are unstable and may change/vanish without notice"); + eprintln!( + "EXPERIMENTAL: filter programs are unstable and may change/vanish without notice" + ); let (requester, mut receiver) = Requester::::new(BUFFER); let task = @@ -87,10 +89,7 @@ impl FilterProgs { let name = format!("__watchexec_filter_{n}"); let filter = Filter::Call(name, Vec::new()); let mut errs = Vec::new(); - let filter = defs.clone().finish( - (Vec::new(), (filter, 0..0)), - &mut errs, - ); + let filter = defs.clone().finish((Vec::new(), (filter, 0..0)), &mut errs); if !errs.is_empty() { error!(?errs, "failed to load filter program #{}", n); continue; diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 861bb2e..39462d3 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -46,7 +46,7 @@ async fn init() -> Result { } } - let args = args::get_args(); + let args = args::get_args().await?; let verbosity = args.verbose.unwrap_or(0); if log_on {