Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug(exp) builtin #2112

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions docs/content/manual/v1.6/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2924,13 +2924,24 @@ sections:
This is primarily useful for reductions over a program's
inputs.

- title: "`debug`"
- title: "`debug`, `debug(exp)`"
body: |

Causes a debug message based on the input value to be
produced. The jq executable wraps the input value with
`["DEBUG:", <input-value>]` and prints that and a newline on
stderr, compactly. This may change in the future.
stderr, compactly. This may change in the future. If given
an argument `exp`, the input is fed to `exp` before being
printed, but remains unchanged coming out.

examples:
- program: 'debug'
input: '1588708020'
output: ['["DEBUG:",1588708020]', '1588708020']
- program: 'debug(todate)'
input: '1588708020'
output: ['["DEBUG:","2020-05-05T19:47:00Z"]', '1588708020']


- title: "`stderr`"
body: |
Expand Down
2 changes: 2 additions & 0 deletions src/builtin.jq
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def scan(re):
then [ .captures | .[] | .string ]
else .string
end ;
def debug(f): . as $val | f | debug | $val;

#
# If input is an array, then emit a stream of successive subarrays of length n (or less),
# and similarly for strings.
Expand Down