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:
parent
dcceaa4b35
commit
26c594feb1
@ -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
|
||||
|
9
pkg/interp/testdata/string_input.fqtest
vendored
9
pkg/interp/testdata/string_input.fqtest
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user