Process all .jsonnet files in directory

1,456 views
Skip to first unread message

Doug Garstang

unread,
May 6, 2016, 1:01:31 PM5/6/16
to Jsonnet
All,

I want jsonnet to process all the .jsonnet files in a directory, and merge them all together into a single output file. Does the jsonnet binary have a native way of doing that? It doesn't like me calling it with 'jsonnet *.jsonnet.

Thanks,
Doug.


Dave Cunningham

unread,
May 6, 2016, 2:25:52 PM5/6/16
to Doug Garstang, Jsonnet
The only way to do that right now is to create a root jsonnet file which imports the others.

We have previously considered adding a feature to allow you to import a directory, which would yield an object whose keys were the filenames.  However this is a bit of a can of worms:

- Just *.jsonnet files or every file (it's lazy so if you don't actually inspect the file it won't matter)
- Should it allow importing a wildcard?
- Add the same feature for importstr?
- What about dirs containing a mixture of text and jsonnet files?
- Should it be recursive?

What you're suggesting is much less of a can of worms because it's an explicit list of files on the commandline, and it's safe to assume they're all Jsonnet files (otherwise what can we actually do with them).  However it wouldn't be possible to do the same thing from within the language itself, which might be a bit weird.

Without any of this, there is still a simple hack you can do: (If you want to output it as an array instead, you can tweak it.)

dcunnin@casterly:~/tmp$ cat a.jsonnet
"a"
dcunnin@casterly:~/tmp$ cat b.jsonnet
"b"
dcunnin@casterly:~/tmp$ jsonnet -e -- "$(ls *.jsonnet | sed -e '1i{' -e 's/.*/    "&": import "&",/' -e '$a}')"
{
   "a.jsonnet": "a",
   "b.jsonnet": "b"
}



--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To post to this group, send email to jso...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/654fa91d-807d-48b1-adbd-bd2d7133b9a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages