collect: don't require a closure (#12788)

# Description

This changes the `collect` command so that it doesn't require a closure.
Still allowed, optionally.

Before:

```nushell
open foo.json | insert foo bar | collect { save -f foo.json }
```

After:

```nushell
open foo.json | insert foo bar | collect | save -f foo.json
```

The closure argument isn't really necessary, as collect values are also
supported as `PipelineData`.

# User-Facing Changes
- `collect` command changed

# Tests + Formatting
Example changed to reflect.

# After Submitting
- [ ] release notes
- [ ] we may want to deprecate the closure arg?
This commit is contained in:
Devyn Cairns
2024-05-17 09:46:03 -07:00
committed by GitHub
parent e3db6ea04a
commit c10aa2cf09
3 changed files with 106 additions and 43 deletions

View File

@ -245,11 +245,15 @@ impl Command for Save {
Ok(PipelineData::empty())
}
input => {
check_saving_to_source_file(
input.metadata().as_ref(),
&path,
stderr_path.as_ref(),
)?;
// It's not necessary to check if we are saving to the same file if this is a
// collected value, and not a stream
if !matches!(input, PipelineData::Value(..) | PipelineData::Empty) {
check_saving_to_source_file(
input.metadata().as_ref(),
&path,
stderr_path.as_ref(),
)?;
}
let bytes =
input_to_bytes(input, Path::new(&path.item), raw, engine_state, stack, span)?;