Add filename/line functions to jq (fix #753)

This adds `input_filename` and `input_line_number` built-in functions
for use in, for example, `error` messages.

Example:

    $ printf '{"a":1}\n{"a":2}\n' > 4.json
    $ printf '{"a":"hello"}\n' > 5.json
    $ ./jq '{ "file":input_filename, "line":input_line_number, "value":.a }' 4.json 5.json
    {
      "file": "4.json",
      "line": 1,
      "value": 1
    }
    {
      "file": "4.json",
      "line": 2,
      "value": 2
    }
    {
      "file": "5.json",
      "line": 1,
      "value": "hello"
    }
This commit is contained in:
Assaf Gordon authored and Nicolas Williams committed 2015-05-21 00:49:32 -05:00
1 parent c7f063188f
commit d1cb8ee0ad
5 files changed
+53

No files matched your search

+9
View File
@@ -1173,3 +1173,12 @@ import "test_bind_order" as check; check::check
null
true
try input_filename catch .
null
"Unknown input filename"
try input_line_number catch .
null
"Unknown input line number"