Skip to content

Commit 9281317

Browse files
authored
Add release note for changes to parse (#1428)
1 parent de9c1eb commit 9281317

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

blog/2024-05-28-nushell_0_94_0.md

+33
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The `dataframes` cargo feature [has been removed in this release](#removal-of-de
4141
- [_`debug profile --lines`_](#debug-profile-lines-toc)
4242
- [_Changes to existing commands_](#changes-to-existing-commands-toc)
4343
- [_Making range semantics consistent_](#making-range-semantics-consistent-toc)
44+
- [_`parse`_](#parse-toc)
4445
- [_`scope commands`_](#scope-commands-toc)
4546
- [_`which`_](#which-toc)
4647
- [_`describe`_](#describe-toc)
@@ -255,6 +256,38 @@ Ranges are inclusive in the upper bound by default in Nushell (e.g., `1..2` or `
255256

256257
To specify an exclusive upperbound, use the `..<` form for ranges (e.g., `1..<2`).
257258

259+
#### `parse` [[toc](#table-of-content)]
260+
261+
::: warning Breaking change
262+
See a full overview of the [breaking changes](#breaking-changes)
263+
:::
264+
265+
To support streaming output, `parse` now operates/matches on a single line at a time **only if provided with the streaming output of an external command, file, or raw byte stream**.
266+
For example, these snippets will try to match each line separately:
267+
```nushell
268+
^cat file.txt | parse -r "some regex"
269+
^cat file.txt | take 1024 | parse -r "some regex"
270+
271+
open file.txt | parse -r "some regex"
272+
open --raw file.txt | parse -r "some regex"
273+
open --raw file.txt | skip 1024 | parse -r "some regex"
274+
```
275+
276+
The old behavior was to collect all of the output the external command or byte stream and then run the regex across the whole string. To mimic this behavior, you can use the `collect` command or store the output in a variable:
277+
```nushell
278+
^cat file.txt | collect | parse -r "some regex"
279+
let text = open file.txt
280+
$text | parse -r "some regex"
281+
```
282+
283+
Note that this change does not affect normal value streams like
284+
```nushell
285+
[(open foo.txt) (open bar.txt)] | parse -r "..."
286+
```
287+
In this case, the regex is run once per string value in the stream and does a multi-line match over the contents of each string.
288+
289+
Note that `parse` may see more breaking changes in the next release to simplify this behavior.
290+
258291
#### `scope commands` [[toc](#table-of-content)]
259292

260293
::: warning Breaking change

0 commit comments

Comments
 (0)