From 179ea5ae8759791995440c3c0c883fa56ab5d95c Mon Sep 17 00:00:00 2001 From: Kumar Ujjawal Date: Mon, 2 Jun 2025 23:48:02 +0530 Subject: [PATCH] fix(which): remove required positional argument to allow spread input (#15870) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This PR removes the required positional argument from the `which` command, allowing it to accept input via the spread (`...`) operator. This enables expressions like: ```nu [notepad cmd] | which ...$in ``` Previously, this failed due to a missing required positional argument. The Nushell runtime already handles empty input gracefully, so the change aligns with existing behavior. --- ## Motivation Making `which` compatible with splatted input improves composability and aligns with user expectations in scriptable environments. It supports patterns where the input may be constructed dynamically or piped in from earlier commands. --- ## Changes * Removed the `required` attribute from the positional argument in the `which` command signature. * No additional runtime logic required since empty input is handled gracefully already. --- ## Examples ### Before ```nu [notepad cmd] | which ...$in # ❌ Error: Missing required positional argument ``` ### After ```nu [notepad cmd] | which ...$in # ✅ Executes correctly ``` --- ## Testing * Ran `cargo test --all` and `cargo test -p nu-command` * Manually tested using spread input with the `which` command * Confirmed that empty and non-empty inputs behave correctly --- ## Related Issues Closes [[#15801](https://github.com/nushell/nushell/issues/15801)](https://github.com/nushell/nushell/issues/15801) --------- Co-authored-by: Kumar Ujjawal --- crates/nu-command/src/system/which_.rs | 3 +-- crates/nu-command/tests/commands/which.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/system/which_.rs b/crates/nu-command/src/system/which_.rs index f5123dd3b6f..297c7f13ec6 100644 --- a/crates/nu-command/src/system/which_.rs +++ b/crates/nu-command/src/system/which_.rs @@ -14,8 +14,7 @@ impl Command for Which { Signature::build("which") .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) - .required("application", SyntaxShape::String, "Application.") - .rest("rest", SyntaxShape::String, "Additional applications.") + .rest("applications", SyntaxShape::String, "Application(s).") .switch("all", "list all executables", Some('a')) .category(Category::System) } diff --git a/crates/nu-command/tests/commands/which.rs b/crates/nu-command/tests/commands/which.rs index 45fdbf59d9e..eb92595e14c 100644 --- a/crates/nu-command/tests/commands/which.rs +++ b/crates/nu-command/tests/commands/which.rs @@ -105,3 +105,16 @@ fn do_not_show_hidden_commands() { let length: i32 = actual.out.parse().unwrap(); assert_eq!(length, 0); } + +#[test] +fn which_accepts_spread_list() { + let actual = nu!( + cwd: ".", // or any valid path + r#" + let apps = [ls]; + $apps | which ...$in | get command.0 + "# + ); + + assert_eq!(actual.out, "ls"); +}