tera-cli icon indicating copy to clipboard operation
tera-cli copied to clipboard

Allow multiple context(s)

Open IgnisDa opened this issue 3 years ago • 3 comments

Awesome library!

I have my data spread over multiple files. But I can specify only one value for context. This is blocking me from using this cli.

IgnisDa avatar Jul 24 '22 05:07 IgnisDa

This is not supported on purpose since you can already do that using jq. Check out the --slurp flags. It will allow bringing all your files into a single context.

chevdor avatar Jul 24 '22 19:07 chevdor

(late reply) This would actually be really nice as I might have a mix of JSON and YAML config files in a few directories representing a hierarchy of configs.

I'm currently doing this as:

    yq \
        --output-format json \
        eval-all \
        '. as $item ireduce ({}; . * $item )' \
        "${ROOT_CONFIG.yaml}" \
        "${LEVEL_ONE_CONFIG.json}" \
        "${LEVEL_TWO_CONFIG.yaml}" \
    | \
    tera \
        --template "${TEMPLATE_FILE}" \
        --out "${CONFIG_FILE}" \
        --stdin

But it would be cool to avoid the whole yq and merge logic in there? Or do we think relying on an external process to merge the data structures is the best approach.

michael-robbins avatar Sep 12 '23 10:09 michael-robbins

The best way to go is to pick your format, whether json or yaml. Then using tools like jq (I think yq does that to and if not, a round thru jq will do), it is possble to use slurp or slurpfile to aggregate a bunch of json into a single one. I don't think that making the decisions on how this aggregation should be done, should be performed by the cli.

For instance, you may prefer to aggregate your "sub-json" into an array, or an object... this is out of the scope of the cli. So in the end, it remains your task to build one context.

chevdor avatar Sep 12 '23 12:09 chevdor