Skip to content

fix(which): remove required positional argument to allow spread input - #15870

Merged
sholderbach merged 3 commits into
nushell:mainfrom
kumarUjjawal:main
Jun 2, 2025
Merged

sholderbach merged 3 commits into
nushell:mainfrom
kumarUjjawal:main

Conversation

@kumarUjjawal

Copy link
Copy Markdown
Contributor

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:

[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

[notepad cmd] | which ...$in
# ❌ Error: Missing required positional argument

After

[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](#15801)

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tackling this!

Signature::build("which")
.input_output_types(vec![(Type::Nothing, Type::table())])
.allow_variants_without_examples(true)
.required("application", SyntaxShape::String, "Application.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the documentation on rest to reflect something like Application(s).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I've updated the doc and pushed the changes. Let me know if anything else needs tweaking.

}

#[test]
fn which_accepts_splatted_list() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: for consistency as we refer to it as the spread operator.

Suggested change
fn which_accepts_splatted_list() {
fn which_accepts_spread_list() {

@sholderbach sholderbach linked an issue Jun 2, 2025 that may be closed by this pull request
@kumarUjjawal

Copy link
Copy Markdown
Contributor Author

@sholderbach fixed the issue should pass now.

@kumarUjjawal

Copy link
Copy Markdown
Contributor Author

@sholderbach my local tests are passing without any issues, is there something I am missing here?

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently encountered some issues with this unrelated commands::job::killing_job_kills_pids test being flaky. Not your problem to worry about here. Started a rerun, should resolve.

@sholderbach sholderbach changed the title fix(which): remove required positional argument to allow splatted input fix(which): remove required positional argument to allow spread input Jun 2, 2025
@sholderbach
sholderbach merged commit 179ea5a into nushell:main Jun 2, 2025
@github-actions github-actions Bot added this to the v0.105.0 milestone Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smarter use of the spread operator

2 participants