Add --slurp flag to read the input stream as one array - #126
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #29.
jqhas a--slurpmode that folds a whole stream of values into one array so the filter runs against the array as a whole. This adds the same option to jnv as-s/--slurp.Right now feeding JSON Lines runs the filter once per value. With
--slurpthe input becomes a single array first, solength,add,sort_by(...)and friends see the whole thing.The fold happens once, just after the input is read and before it reaches the viewer and the completion loader, so nothing downstream changed. It honors
max_streamslike the normal path does, so I moved the config load a few lines up to have that value on hand (that also means a broken config is reported before we read stdin).There was no test target yet, so I added the first unit tests, covering the slurp helper for empty input, JSON Lines, a single value, the
max_streamsbound and invalid input.cargo fmt --check,cargo clippy,cargo testandcargo buildall pass. I couldn't drive the full TUI headless, so the wiring is covered by compilation and those tests rather than a live run.