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

@ -84,7 +84,7 @@ fn save_append_will_not_overwrite_content() {
}
#[test]
fn save_stderr_and_stdout_to_afame_file() {
fn save_stderr_and_stdout_to_same_file() {
Playground::setup("save_test_5", |dirs, sandbox| {
sandbox.with_files(&[]);
@ -424,3 +424,42 @@ fn save_with_custom_converter() {
assert_eq!(actual, r#"{"a":1,"b":2}"#);
})
}
#[test]
fn save_same_file_with_collect() {
Playground::setup("save_test_20", |dirs, _sandbox| {
let actual = nu!(
cwd: dirs.test(), pipeline("
echo 'world'
| save hello;
open hello
| prepend 'hello'
| collect
| save --force hello;
open hello
")
);
assert!(actual.status.success());
assert_eq!("helloworld", actual.out);
})
}
#[test]
fn save_same_file_with_collect_and_filter() {
Playground::setup("save_test_21", |dirs, _sandbox| {
let actual = nu!(
cwd: dirs.test(), pipeline("
echo 'world'
| save hello;
open hello
| prepend 'hello'
| collect
| filter { true }
| save --force hello;
open hello
")
);
assert!(actual.status.success());
assert_eq!("helloworld", actual.out);
})
}