From 5db57abc7d813c7b0bb56709379ea82a4b85b4eb Mon Sep 17 00:00:00 2001 From: Zoey Hewll Date: Sat, 20 Jul 2024 18:34:27 +0800 Subject: [PATCH] add --quiet flag to `watch` command (#13415) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Adds a `--quiet` flag to the `watch` command, silencing the message usually shown when invoking `watch`. Resolves #13411 As implemented, `--quiet` is orthogonal to `--verbose`. I'm open to improving the flag's name, behaviour and/or documentation to make it more user-friendly, as I realise this may be surprising as-is. ``` > watch path {|a b c| echo $a $b $c} Now watching files at "/home/user/path". Press ctrl+c to abort. ───┬─────────────────────── 0 │ Remove 1 │ /home/user/path 2 │ ───┴─────────────────────── ^C > watch --quiet path {|a b c| echo $a $b $c} ───┬─────────────────────── 0 │ Remove 1 │ /home/user/path 2 │ ───┴─────────────────────── ^C ``` # User-Facing Changes Adds `--quiet`/`-q` flag to `watch`, which removes the initial status message. --- crates/nu-command/src/filesystem/watch.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filesystem/watch.rs b/crates/nu-command/src/filesystem/watch.rs index c9817de2500..e6d86357b84 100644 --- a/crates/nu-command/src/filesystem/watch.rs +++ b/crates/nu-command/src/filesystem/watch.rs @@ -61,6 +61,7 @@ impl Command for Watch { "Watch all directories under `` recursively. Will be ignored if `` is a file (default: true)", Some('r'), ) + .switch("quiet", "Hide the initial status message (default: false)", Some('q')) .switch("verbose", "Operate in verbose mode (default: false)", Some('v')) .category(Category::FileSystem) } @@ -94,6 +95,8 @@ impl Command for Watch { let verbose = call.has_flag(engine_state, stack, "verbose")?; + let quiet = call.has_flag(engine_state, stack, "quiet")?; + let debounce_duration_flag: Option> = call.get_flag(engine_state, stack, "debounce-ms")?; let debounce_duration = match debounce_duration_flag { @@ -161,7 +164,9 @@ impl Command for Watch { // need to cache to make sure that rename event works. debouncer.cache().add_root(&path, recursive_mode); - eprintln!("Now watching files at {path:?}. Press ctrl+c to abort."); + if !quiet { + eprintln!("Now watching files at {path:?}. Press ctrl+c to abort."); + } let mut closure = ClosureEval::new(engine_state, stack, closure);