j2cli
j2cli copied to clipboard
Support multiple data files
It'd be nice to support multiple input data files instead of just one.
This could be achieved by adopting the following format:
- [filename] - load the file at the root of the data tree using default type spec, overwriting/merging with any prior files
- [type]=[filename] - Load the filename as format [type] (overrides -f)
- [type]@[loc]=[filename] - Load the filename as format [type] into the data tree at location [loc]
- @[loc]=[filename] - Load the filename as default format (specified with -f) into the data tree at location [loc]
Hmm this is a bit of an issue with envtpl (now unmaintained) I cannot simply convert over as I would have.
ie:
JSON_FILE1=$(<jsonfile1.json) \
JSON_FILE2=$(<jsonfile2.json) \
envtpl --keep-template ~/template.j2 -o ~/output.txt
If I have two for loops that use different JSON source data.
Just letting you know you can do this to merge your files and take in via stdin using jq:
For two files:
jq -rs 'reduce .[] as $item ({}; . * $item)' "file1.json file2.json" \
| j2 -f json -o output.txt input.j2
For any number of files:
jq -rs 'reduce .[] as $item ({}; . * $item)' ./*.json \
| j2 -f json -o output.txt input.j2
But what if I wanted to use yaml (or toml.. or) :( - I would very much prefer to be able to specify multiple data files. This would be very useful, f.ex. if I want to generate 10 files, and have a common dataset for all 10 files - I'd like to only keep in one file - and then keep only variations in the 10 data files.. so I'd have:
common.yaml: key1: value1 key2: value2 ... key99: value99
file1.yaml: file1key: somevalue
So when I render file1 - I'd also give j2cli 2 data files: file1.yaml and common.yaml - to avoid having the common values in all 10 datafiles.
Hi! This project gets some interest, but sadly, I'm not maintaining it =\
Maintainer wanted! Discussion: Maintainer Wanted