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

Implement --experimental-fileargs cli option #3167

Closed
wants to merge 2 commits into from

Conversation

myaaaaaaaaa
Copy link
Contributor

@myaaaaaaaaa myaaaaaaaaa commented Aug 30, 2024

A combination of --jsonargs and --slurpfile. Slurps all json files passed as a command line argument, and makes them available under $ARGS.named[filename].

$ jq -n '{"a":"a"}' >a.json
$ jq -n '{"b":"b"}' >b.json
$ jq -n --experimental-fileargs '$ARGS.named' *.json

{
	"a.json": [
		{
			"a": "a"
		}
	],
	"b.json": [
		{
			"b": "b"
		}
	]
}

Using this over an input builtin allows easy access to filesystem functionality such as find and globbing, without having to implement them as jq builtins. Files can also be written-in-place when using snapshots ( #3165 ), since all inputs are read before any writes happen.

Depends on #3165 for tests, marking as draft until that one is merged.

@wader
Copy link
Member

wader commented Sep 19, 2024

Maybe not superelegant but one can do this:

$ jq -n '[inputs | {(input_filename): .}] | add' <(echo 1) <(echo 2)
{
  "/dev/fd/11": 1,
  "/dev/fd/12": 2
}

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

Successfully merging this pull request may close these issues.

2 participants