From 6cd2252b6c15a969288c16268e596d84cc4815de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Fri, 24 Dec 2021 03:56:03 +1300 Subject: [PATCH] Modify options available if tagged filterer enabled --- cli/src/args.rs | 98 ++++++++++++++++++++++++++++++++++--------------- cli/src/main.rs | 23 ++++++------ 2 files changed, 80 insertions(+), 41 deletions(-) diff --git a/cli/src/args.rs b/cli/src/args.rs index bb0d6eb..939e416 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -27,7 +27,7 @@ const OPTSET_DEBUGGING: &str = "Debugging options:"; const OPTSET_OUTPUT: &str = "Output options:"; const OPTSET_BEHAVIOUR: &str = "Behaviour options:"; -pub fn get_args() -> Result> { +pub fn get_args(tagged_filterer: bool) -> Result> { let app = App::new("watchexec") .version(crate_version!()) .about("Execute commands when watched files change") @@ -37,12 +37,6 @@ pub fn get_args() -> Result> { .help("Command to execute") .multiple(true) .required(true)) - .arg(Arg::with_name("extensions") - .help_heading(Some(OPTSET_FILTERING)) - .help("Comma-separated list of file extensions to watch (e.g. js,css,html)") - .short("e") - .long("exts") - .takes_value(true)) .arg(Arg::with_name("paths") .help_heading(Some(OPTSET_FILTERING)) .help("Watch a specific file or directory") @@ -100,24 +94,6 @@ pub fn get_args() -> Result> { .help("Print events that trigger actions") .long("print-events") .alias("changes-only")) // --changes-only is deprecated (remove at v2) - .arg(Arg::with_name("filter") // TODO - .help_heading(Some(OPTSET_FILTERING)) - .help("Ignore all modifications except those matching the pattern") - .short("f") - .long("filter") - .number_of_values(1) - .multiple(true) - .takes_value(true) - .value_name("pattern")) - .arg(Arg::with_name("ignore") // TODO - .help_heading(Some(OPTSET_FILTERING)) - .help("Ignore modifications to paths matching the pattern") - .short("i") - .long("ignore") - .number_of_values(1) - .multiple(true) - .takes_value(true) - .value_name("pattern")) .arg(Arg::with_name("no-vcs-ignore") // TODO .help_heading(Some(OPTSET_FILTERING)) .help("Skip auto-loading of .gitignore files for filtering") @@ -155,10 +131,6 @@ pub fn get_args() -> Result> { .help("Do not wrap command in a shell. Deprecated: use --shell=none instead.") .short("n") .long("no-shell")) - .arg(Arg::with_name("no-meta") // TODO - .help_heading(Some(OPTSET_FILTERING)) - .help("Ignore metadata changes") - .long("no-meta")) .arg(Arg::with_name("no-environment") // TODO .help_heading(Some(OPTSET_OUTPUT)) .help("Do not set WATCHEXEC_*_PATH environment variables for the command") @@ -180,6 +152,74 @@ pub fn get_args() -> Result> { .short("N") .long("notify")); + let app = if tagged_filterer { + app.arg( + Arg::with_name("filter") + .help_heading(Some(OPTSET_FILTERING)) + .help("Add tagged filter (e.g. 'path=foo*', 'type=dir', 'kind=Create(*)')") + .short("f") + .long("filter") + .number_of_values(1) + .multiple(true) + .takes_value(true) + .value_name("tagged filter"), + ) + .arg( + Arg::with_name("filter-files") // TODO + .help_heading(Some(OPTSET_FILTERING)) + .help("Load tagged filters from a file") + .short("F") + .long("filter-file") + .number_of_values(1) + .multiple(true) + .takes_value(true) + .value_name("path"), + ) + .arg( + Arg::with_name("no-meta") // TODO + .help_heading(Some(OPTSET_FILTERING)) + .help("Ignore metadata changes (equivalent of `-f 'kind*!Modify(Metadata(*))'`)") + .long("no-meta"), + ) + } else { + app.arg( + Arg::with_name("extensions") + .help_heading(Some(OPTSET_FILTERING)) + .help("Comma-separated list of file extensions to watch (e.g. js,css,html)") + .short("e") + .long("exts") + .takes_value(true), + ) + .arg( + Arg::with_name("filter") // TODO + .help_heading(Some(OPTSET_FILTERING)) + .help("Ignore all modifications except those matching the pattern") + .short("f") + .long("filter") + .number_of_values(1) + .multiple(true) + .takes_value(true) + .value_name("pattern"), + ) + .arg( + Arg::with_name("ignore") // TODO + .help_heading(Some(OPTSET_FILTERING)) + .help("Ignore modifications to paths matching the pattern") + .short("i") + .long("ignore") + .number_of_values(1) + .multiple(true) + .takes_value(true) + .value_name("pattern"), + ) + .arg( + Arg::with_name("no-meta") // TODO + .help_heading(Some(OPTSET_FILTERING)) + .help("Ignore metadata changes") + .long("no-meta"), + ) + }; + let mut raw_args: Vec = env::args_os().collect(); if let Some(first) = raw_args.get(1).and_then(|s| s.to_str()) { diff --git a/cli/src/main.rs b/cli/src/main.rs index 8f0c39d..9927844 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -20,7 +20,11 @@ async fn main() -> Result<()> { tracing_subscriber::fmt::init(); } - let args = args::get_args()?; + let tagged_filterer = var("WATCHEXEC_FILTERER") + .map(|v| v == "tagged") + .unwrap_or(false); + + let args = args::get_args(tagged_filterer)?; tracing_subscriber::fmt() .with_env_filter(match args.occurrences_of("verbose") { @@ -34,17 +38,12 @@ async fn main() -> Result<()> { let init = config::init(&args)?; let mut runtime = config::runtime(&args)?; - runtime.filterer( - if var("WATCHEXEC_FILTERER") - .map(|v| v == "tagged") - .unwrap_or(false) - { - eprintln!("!!! EXPERIMENTAL: using tagged filterer !!!"); - filterer::tagged(&args).await? - } else { - filterer::globset(&args).await? - }, - ); + runtime.filterer(if tagged_filterer { + eprintln!("!!! EXPERIMENTAL: using tagged filterer !!!"); + filterer::tagged(&args).await? + } else { + filterer::globset(&args).await? + }); let wx = Watchexec::new(init, runtime)?;