Skip to content

feat: enable spread operator for get command rest args - #18220

Merged
fdncred merged 4 commits into
nushell:mainfrom
mvanhorn:fix/15801-enable-spread-operator-for-get-command-rest-args
Oct 19, 2026
Merged

fdncred merged 4 commits into
nushell:mainfrom
mvanhorn:fix/15801-enable-spread-operator-for-get-command-rest-args

Conversation

@mvanhorn

@mvanhorn mvanhorn commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

get now takes its cell paths as a single ...rest parameter, so a list of paths can be spread into it: get ...$paths. Before this, get required a first cell path followed by a rest, and there was no way to pass a dynamically built list of paths.

Behavior

  • get with no paths returns its input unchanged. With an empty pipeline it reports Pipeline empty, the same as select.
  • get a with one cell path and no spread returns the value at that path, as before.
  • Several paths, or any spread argument, return a list with one value per path. A spread always produces a list, so get ...$cols has the same shape whatever $cols holds: one name gives a one-element list, and an empty spread gives an empty list.
  • Strings in a spread are single column names, so ...[a.b] looks for a column named a.b. Nested paths are spread as cell-path values, for example let paths = [$.a.b] or into cell-path.

Changes

  • crates/nu-command/src/filters/get.rs: the signature is get ...(rest). action takes the full Vec<CellPath>, checks for an empty pipeline first, then branches on zero paths, one path without a spread, and everything else. A small helper reads whether the call has a spread argument (AST and IR calls). The help text and examples describe the zero, one and many cases and nested spread paths.
  • crates/nu-command/tests/commands/get.rs: tests for literal before and after a spread, one-element spreads on a table and a record, empty literal and variable spreads, a nested cell-path spread, a const spread, and the empty pipeline with no paths and with an empty spread.

Testing

On the merged branch: cargo fmt --all -- --check, cargo clippy -p nu-command --all-targets -- -D warnings (with .cargo/ci.toml), cargo test -p nu-command --test tests -- commands::get (39 passed) and the get examples test all pass. Against the previous get.rs, 8 of the 10 new tests fail; the two mixed-order tests pass on both, since that ordering already worked.

User-facing changes (Release notes)

get accepts spread cell paths: get ...$paths

  • get accepts spread cell paths (get ...$paths). Its signature changes from get <cell_path> ...(rest) to get ...(rest).
  • get with no arguments is no longer a parse error: it returns its input, or reports Pipeline empty when there is no input.
  • A get call with a spread argument always returns a list, one value per path.

Fixes #15801

@github-actions github-actions Bot added the A:parser Issues related to parsing label May 16, 2026
Comment thread crates/nu-command/src/filters/get.rs Resolved
mvanhorn added a commit to mvanhorn/nushell that referenced this pull request May 17, 2026
Per @Juhan280 review comment on get.rs:234 in nushell#18220.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Fixed in 3c79d5f - swapped AccessEmptyContent for MissingParameter { param_name: "cell_path".into(), span }. cargo check -p nu-command is clean.

@fdncred

fdncred commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

I think this is probably a pretty good change because it brings get and select closer to the same syntax, since select already supports ...rest. If you can get the CI green, we can probably land this.

@mvanhorn

mvanhorn commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @fdncred! The only failing check was cargo fmt --all --check on the MissingParameter literal my last commit added in split_cell_paths (get.rs:231). Ran cargo fmt and pushed 485f347. cargo fmt --all --check and cargo check -p nu-command are both clean locally now, so CI should be green.

@fdncred

fdncred commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@mvanhorn it seems there is at least one test with spread that you haven't addressed. bad_spread_internal_args

@mvanhorn

mvanhorn commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up addressing the bad_spread_internal_args failure properly. The earlier revision allowed a spread to satisfy required positionals at parse time but left them null at runtime. Spread elements are now distributed into unfilled required positionals at binding time (eval and IR paths), so def f [a b c? d? ...x] {}; f 1 ...[5 6] binds a=1, b=5, x=[6]. Scope is deliberately narrow for compatibility: only required positionals are fillable from a spread (those calls were parse errors before, so nothing depended on them); optional positionals and post-spread behavior are unchanged, and all pre-existing spread test expectations pass as-is. A spread too short to cover the remaining required positionals errors with the missing parameter name. This is what makes get ...$columns work with get's required cell_path + rest signature.

@mvanhorn

mvanhorn commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

CI is green again in 9bb700e. Root cause: the binding-time distribution change was type-checking optional positionals against their declared variable type, which std's assert internals trip over (cant_convert in try/catch paths). check_type now only runs for required positionals, matching the previous binding behavior for optionals. Verified locally: full std suite, get command tests (154), and spread tests (17) all pass.

@Bahex

Bahex commented Jun 6, 2026

Copy link
Copy Markdown
Member

I'm fine with making get similar to select by changing its signature from

get <cell-path> ...(rest)

to

get ...(rest)

and making get without arguments a no-op (like select).

I really don't like the changes to how parameters in general are handled.
Aside from weakening the type system (which I can accept, in a shell that's primarily used as a repl convenience can trump rigor), I find it unintuitive for spread operator to:

  • fill missing required positional parameters
  • skip optional positional parameters
  • fill the ...(rest) parameter

@mvanhorn

Copy link
Copy Markdown
Contributor Author

That works for me - I'd rather not weaken the general parameter binding either, and the fill-required / skip-optional / then-fill-rest ordering is genuinely surprising. Pushed the rework in bf89c46: get is now get ...(rest) with a no-op on empty (like select), and I reverted the eval/eval_ir/parser spread changes back to upstream - so get ...$columns spreads straight into the rest arg with no changes to how positionals bind. Verified locally: nu-command builds clean and all 27 get command tests pass (spread + no-op cases included).

@mvanhorn

mvanhorn commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged main into the branch (5ec4e28). It had gone 330 commits stale and conflicted in tests/commands/get.rs; resolved, and it's mergeable again.

The rework we settled on is unchanged: get is still get ...(rest) with no arguments as a no-op.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Mixed literal/spread ordering and actual empty-spread syntax remain untested.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Enables get to accept spread cell-path arguments by making paths variadic and handling empty path lists as identity operations.

Changes:

  • Flattens spread paths for runtime and const evaluation.
  • Adds spread and no-path behavior tests/examples.
File summaries
File Description
crates/nu-command/src/filters/get.rs Supports variadic and empty cell paths.
crates/nu-command/tests/commands/get.rs Tests spread and identity behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/nu-command/tests/commands/get.rs Resolved
@fdncred

fdncred commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Are we still moving forward here? Looks like there are conflicts. Please rebase on main, get the CI green and I'd like to do one more review.

Make get's signature `get ...(rest)`, matching select: `get ...$columns`
spreads straight into the rest argument, and `get` with no cell paths
returns its input unchanged. Parameter binding is unchanged.

Rebased onto main as a single commit. The earlier spread-binding
experiments on this branch were reverted in review and are dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KFTE4BHbGYzgf8Uhzcppdh
@mvanhorn
mvanhorn force-pushed the fix/15801-enable-spread-operator-for-get-command-rest-args branch from 5ec4e28 to 65a695c Compare October 15, 2026 23:23
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Rebased onto main in 65a695c and resolved the conflict in get.rs, where run_const now takes the new stack argument. cargo build, cargo fmt --check, clippy and the full workspace tests are green here. Ready for another look.

@fdncred

fdncred commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

ok, let's do one more review.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review overview

🟡 Changes recommended

The spread works and the tests pass, but the result's shape now depends on how long the spread list is at runtime, and get with no paths skips the empty-pipeline error that select reports.

Findings: 1 High severity · 2 Medium severity · 5 Low severity

Open (8)

Notes from my clanker, checked on 65a695c. Built the branch; the 29 commands::get tests and test_examples pass; probed spread, empty, null, const and stream cases on the branch binary and on 0.116.2.

Comment thread crates/nu-command/src/filters/get.rs Resolved
Comment thread crates/nu-command/src/filters/get.rs Resolved
Comment thread crates/nu-command/src/filters/get.rs Resolved
Comment thread crates/nu-command/src/filters/get.rs Resolved
Comment thread crates/nu-command/src/filters/get.rs Resolved
Comment thread crates/nu-command/src/filters/get.rs Resolved
…first

Address review:

- A call with a spread argument now always returns one value per path,
  so `get ...$cols` has the same shape whether $cols holds zero, one or
  many names. An empty spread returns an empty list; bare `get` still
  returns its input.
- The no-path case moves into `action`, after the PipelineData::Empty
  check, so `get` and `get ...[]` with no input report Pipeline empty
  like `select` does. This fixes `run` and `run_const` in one place.
- `action` takes the Vec<CellPath> directly, which removes
  split_cell_paths and its let-else blocks.
- The help text says what zero, one and several paths return, and that
  spread strings are single column names, with a `$.a.b` example for
  nested paths. The spread examples use Value::test_list.
- Tests cover literal before and after a spread, one-element and empty
  spreads (literal and variable), nested cell-path spreads, a const
  spread, and the empty pipeline with no paths and with an empty spread.
@fdncred

fdncred commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

when you're done, please respond to each review comment so we can be sure nothing was missed

The help text said "With one literal cell path", but the fast path also
applies to a single cell path held in a variable. Say "With one cell path
and no spread" instead, as suggested in review.
@fdncred fdncred added the notes:breaking-changes Noted in Breaking Changes section label Oct 19, 2026
@fdncred
fdncred merged commit 04ba983 into nushell:main Oct 19, 2026
11 checks passed
@fdncred

fdncred commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 19, 2026
@fdncred

fdncred commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Please change the PR body to follow the PR template since we use that for release notes.

@kronberger-droid kronberger-droid added the notes:ready Indicates Ready for Release notes label Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing notes:breaking-changes Noted in Breaking Changes section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smarter use of the spread operator

6 participants