From 30dae61a02a4a48b73e63a238dad81421880cc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Tue, 28 Sep 2021 22:24:06 +1300 Subject: [PATCH] Add filtering to demo CLI --- cli/src/config.rs | 18 ++++++++++++------ cli/src/main.rs | 6 +++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cli/src/config.rs b/cli/src/config.rs index c036fbf..294e3f9 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -1,5 +1,6 @@ use std::{ - convert::Infallible, env::current_dir, io::stderr, path::Path, str::FromStr, time::Duration, + convert::Infallible, env::current_dir, io::stderr, path::Path, str::FromStr, sync::Arc, + time::Duration, }; use clap::ArgMatches; @@ -8,13 +9,15 @@ use watchexec::{ action::{Action, Outcome, Signal}, command::Shell, config::{InitConfig, RuntimeConfig}, + filter::tagged::TaggedFilterer, fs::Watcher, handler::PrintDisplay, signal::Signal as InputSignal, }; -pub fn new(args: &ArgMatches<'static>) -> Result<(InitConfig, RuntimeConfig)> { - Ok((init(args)?, runtime(args)?)) +pub fn new(args: &ArgMatches<'static>) -> Result<(InitConfig, RuntimeConfig, Arc)> { + let r = runtime(args)?; + Ok((init(args)?, r.0, r.1)) } fn init(_args: &ArgMatches<'static>) -> Result { @@ -25,7 +28,7 @@ fn init(_args: &ArgMatches<'static>) -> Result { Ok(config.build()?) } -fn runtime(args: &ArgMatches<'static>) -> Result { +fn runtime(args: &ArgMatches<'static>) -> Result<(RuntimeConfig, Arc)> { let mut config = RuntimeConfig::default(); config.command( @@ -90,6 +93,9 @@ fn runtime(args: &ArgMatches<'static>) -> Result { let print_events = args.is_present("print-events"); let once = args.is_present("once"); + let filterer = TaggedFilterer::new(".", "."); + config.filterer(filterer.clone()); + config.on_action(move |action: Action| { let fut = async { Ok::<(), Infallible>(()) }; @@ -180,10 +186,10 @@ fn runtime(args: &ArgMatches<'static>) -> Result { fut }); - Ok(config) + Ok((config, filterer)) } -// until 2.0 +// until 2.0, then Powershell #[cfg(windows)] fn default_shell() -> Shell { Shell::Cmd diff --git a/cli/src/main.rs b/cli/src/main.rs index e62ad10..8caab13 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -28,7 +28,11 @@ async fn main() -> Result<()> { .ok(); } - let (init, runtime) = config::new(&args)?; + let (init, runtime, filterer) = config::new(&args)?; + + for filter in args.values_of("filter").unwrap_or_default() { + filterer.add_filter(filter.parse()?).await?; + } let wx = Watchexec::new(init, runtime)?;