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

Preserve input_filename I/O variable #79

Open
marcel-steinbach-mpf opened this issue Dec 13, 2019 · 1 comment
Open

Preserve input_filename I/O variable #79

marcel-steinbach-mpf opened this issue Dec 13, 2019 · 1 comment

Comments

@marcel-steinbach-mpf
Copy link

jq can sets the variable input_filename, which may be useful when processing multiple files, e.g.

$ echo "{}" > a.json
$ echo "{}" > b.json
$ jq '{ file:input_filename }' {a,b}.json
{
  "file": "a.json"
}
{
  "file": "b.json"
}

(see https://stedolan.github.io/jq/manual/#IO)

yq seems to pipe the contents in which removes the information about the currently processed file:

$ echo '---' > a.yaml
$ echo '---' > b.yaml
$ yq '{ file:input_filename }' {a,b}.yaml
{
  "file": "<stdin>"
}
{
  "file": "<stdin>"
}
@marcel-steinbach-mpf
Copy link
Author

marcel-steinbach-mpf commented Dec 13, 2019

I know this is a fringe case. Not sure how to properly solve this, a workaround would be to pass it as an argument to jq, e.g. --arg input_filename a.json, it would be a different accessor though: { file: $input_filename } (with the $ prefix)

Also, I haven't checked if jq provides some other implicit variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant