itchyny / gojq

Pure Go implementation of jq
MIT License
3.3k stars 119 forks source link

When using `--args` with `-f` the first argument is treated as input file unless you use `--` #228

Closed emanuele6 closed 12 months ago

emanuele6 commented 1 year ago

When using --args in combination with -f, the first positional argument is treated as an input file instead of a positional argument; if you provide -- before positional arguments, it works correctly:

$ gojq -cn --args -f /dev/stdin 1 2 3 <<< '$ARGS, inputs'
{"named":{},"positional":["2","3"]}
gojq: error: open 1: no such file or directory
$ gojq -cn --args -f /dev/stdin -- 1 2 3 <<< '$ARGS, inputs'
{"named":{},"positional":["1","2","3"]}

The problem only occurs if you use -f; if you use an inline script, it works correctly even without --:

$ gojq -cn --args '$ARGS, inputs' 1 2 3 <<< 4
{"named":{},"positional":["1","2","3"]}
4
itchyny commented 12 months ago

I fixed this issue.