1
1
mirror of https://github.com/wader/fq.git synced 2024-12-28 08:02:28 +03:00

Merge pull request #58 from wader/stderr-and-tests

interp: Add stderr again for jq compat
This commit is contained in:
Mattias Wadman 2022-01-07 20:10:30 +01:00 committed by GitHub
commit 6cbd6f6b79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"