Skip to content

Commit

Permalink
fix input_filename for file arguments with null input option (ref #90)
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Nov 24, 2021
1 parent 82fb2f0 commit aa11cd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cli/cli.go
Expand Up @@ -241,12 +241,14 @@ Usage:
gojq.WithFunction("debug", 0, 0, cli.funcDebug),
gojq.WithFunction("stderr", 0, 0, cli.funcStderr),
gojq.WithFunction("input_filename", 0, 0,
func(interface{}, []interface{}) interface{} {
if fname := iter.Name(); fname != "" {
return fname
func(iter inputIter) func(interface{}, []interface{}) interface{} {
return func(interface{}, []interface{}) interface{} {
if fname := iter.Name(); fname != "" && (len(args) > 0 || !opts.InputNull) {
return fname
}
return nil
}
return nil
},
}(iter),
),
gojq.WithInputIter(iter),
)
Expand Down
13 changes: 13 additions & 0 deletions cli/test.yaml
Expand Up @@ -4701,6 +4701,19 @@
"testdata/1.json"
"testdata/2.json"
- name: input_filename function with null input option and json file arguments
args:
- -n
- '., inputs, (try input catch .) | input_filename'
- 'testdata/1.json'
- 'testdata/2.json'
input: '0'
expected: |
null
"testdata/1.json"
"testdata/2.json"
null
- name: input_filename function with hyphen for stdin
args:
- 'input_filename'
Expand Down

0 comments on commit aa11cd7

Please sign in to comment.