1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 13:22:58 +03:00

interp: Add stderr again for jq compat

Also add tests for print* and stderr
This commit is contained in:
Mattias Wadman 2022-01-07 11:01:28 +01:00
parent 2c3e41111d
commit a3cfcd0ad2
2 changed files with 35 additions and 0 deletions

View File

@ -9,11 +9,17 @@ def println: ., "\n" | print;
def printerr: tostring | _stderr;
def printerrln: ., "\n" | printerr;
# jq compat
def debug:
( ((["DEBUG", .] | tojson) | printerrln)
, .
);
def debug(f): . as $c | f | debug | $c;
# jq compat, output to compact json to stderr and let input thru
def stderr:
( (tojson | printerr)
, .
);
def _global_var($k): _global_state[$k];
def _global_var($k; f): _global_state(_global_state | .[$k] |= f) | .[$k];

View File

@ -13,3 +13,32 @@ null> ^D
stderr:
["DEBUG",{"a":123,"b":[]}]
["DEBUG",{"a":123}]
$ fq -n 'null, {a:1}, "abc" | ., "\n" | print'
null
{"a":1}
abc
$ fq -n 'null, {a:1}, "abc" | println'
null
{"a":1}
abc
$ fq -n 'null, {a:1}, "abc" | ., "\n" | printerr'
stderr:
null
{"a":1}
abc
$ fq -n 'null, {a:1}, "abc" | printerrln'
stderr:
null
{"a":1}
abc
$ fq -n 'null, {a:1}, "abc" | ., "\n" | stderr'
null
"\n"
{
"a": 1
}
"\n"
"abc"
"\n"
stderr:
null"\n"{"a":1}"\n""abc""\n"