1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 21:31:33 +03:00

input: make -R mimic jq on io error

This commit is contained in:
Mattias Wadman 2021-09-13 12:12:34 +02:00
parent dcceaa4b35
commit 26c594feb1
2 changed files with 24 additions and 10 deletions

View File

@ -473,25 +473,30 @@ def input:
end
else
( [_repeat_break(_input($opts; tobytes | tostring))]
| join("") as $all
| . as $chunks
| if $opts.slurp then
# jq --raw-input combined with --slurp reads all inputs into a string
# make next input break
( _input_strings_lines([]) as $_
| $all
| $chunks
| join("")
)
else
# TODO: different line endings?
# jq strips last newline, "a\nb" and "a\nb\n" behaves the same
# also jq -R . <(echo -ne 'a\nb') <(echo c) produces "a" and "bc"
( _input_strings_lines(
( $all
| rtrimstr("\n")
| split("\n")
)
) as $_
| input
)
if ($chunks | length) > 0 then
( _input_strings_lines(
( $chunks
| join("")
| rtrimstr("\n")
| split("\n")
)
) as $_
| input
)
else error("break")
end
end
)
end

View File

@ -54,3 +54,12 @@ stdin:
a
b
c
$ fq -R . missing
exitcode: 2
stderr:
error: missing: file not found
$ fq -Rs . missing
""
exitcode: 2
stderr:
error: missing: file not found