{"id":17208638,"url":"https://github.com/chevdor/tera-cli","last_synced_at":"2026-02-18T02:02:10.092Z","repository":{"id":39374301,"uuid":"374141690","full_name":"chevdor/tera-cli","owner":"chevdor","description":"A command line utility on top of the tera templating engine. Takes json|yaml|toml as input and can merge ENV in. You may see it as envsubst on steroid.","archived":false,"fork":false,"pushed_at":"2025-02-10T12:34:15.000Z","size":428,"stargazers_count":82,"open_issues_count":9,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T18:08:40.818Z","etag":null,"topics":["2021","automation","chevdor","ci","cli","engine","rust","stdin","template","template-engine","tera"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chevdor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-05T14:59:07.000Z","updated_at":"2025-03-17T05:24:08.000Z","dependencies_parsed_at":"2024-01-02T13:25:05.546Z","dependency_job_id":"1ac58c8a-7220-480f-bcd4-7fab9983f595","html_url":"https://github.com/chevdor/tera-cli","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chevdor%2Ftera-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chevdor%2Ftera-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chevdor%2Ftera-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chevdor%2Ftera-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chevdor","download_url":"https://codeload.github.com/chevdor/tera-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535517,"owners_count":20954576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2021","automation","chevdor","ci","cli","engine","rust","stdin","template","template-engine","tera"],"created_at":"2024-10-15T02:49:24.129Z","updated_at":"2026-02-18T02:02:05.073Z","avatar_url":"https://github.com/chevdor.png","language":"Rust","readme":"# tera-cli\n\n## Intro\n\n\u003cfigure\u003e\n\u003cimg src=\"resources/logo/tera-cli-logo_256.png\" alt=\"tera cli logo 256\" /\u003e\n\u003c/figure\u003e\n\n[tera](https://github.com/Keats/tera) is a template engine written in Rust and inspired by Jinja2. It allows merging some data called `context data` into a template and produces a new output. This project, `tera-cli`, is a command line for the [tera template engine](https://github.com/Keats/tera).\n\nThis project is called `tera-cli` but the command installed on your system is simply `tera`.\n\n`tera-ci` offers powerful features related to your environment variables, allowing you to control the output **both** from the context data you pass but also from the ENV variables set on your system.\n\n## Example\n\nHere is a basic example. For instance, you will pass data such as:\n\n    .data.json:\n    {\n        \"title\": \"Demo\",\n        \"users\": [\n            {\n                \"username\": \"Alice\",\n                \"url\": \"http://example.org/alice\",\n                \"fav_colors\": [\"red\", \"green\", \"yellow\"]\n            },\n            {\n                \"username\": \"Bob\",\n                \"url\": \"http://example.org/bob\",\n                \"fav_colors\": [\"orange\"]\n            }\n        ]\n    }\n\nas well as a template such as:\n\n    .template.tmpl\n    \u003ctitle\u003e{% block title %} {{title}} {% endblock title %}\u003c/title\u003e\n\n    \u003cul\u003e\n    {% for user in users -%}\n        \u003cli\u003e\u003ca href=\"{{ user.url }}\"\u003e{{ user.username }}\n        {{ user.username }} likes {% for color in user.fav_colors -%}{{ color }} {% endfor %}\n        \u003c/a\u003e\u003c/li\u003e\n    {% endfor %}\n    \u003c/ul\u003e\n\nand a call such as `tera --template template.tera data.json` will produce:\n\n    .result\n    \u003ctitle\u003e Demo \u003c/title\u003e\n\n    \u003cul\u003e\n    \u003cli\u003e\u003ca href=\"http://example.org/alice\"\u003eAlice\n        Alice likes red green yellow\n        \u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"http://example.org/bob\"\u003eBob\n        Bob likes orange\n        \u003c/a\u003e\u003c/li\u003e\n\n    \u003c/ul\u003e\n\nThe **tera** engine allows way more than the simple replacements shown above. You may check out the [doc](https://tera.netlify.app/docs) for more information. To name only a few, **tera** offers the following:\n\n-   variables \u0026 expressions (you can do math…​)\n\n-   comments\n\n-   control structure \u0026 loops (if, for, …​)\n\n-   filters\n\n-   formatting functions (show a file size, format a date, etc…​)\n\n-   inheritance, include, etc…​\n\n-   built-ins: capitalize strings, replace, trim, etc…​\n\n## Install\n\n    cargo install --git https://github.com/chevdor/tera-cli\n\n## Hot reload\n\nYou may find it useful to watch a folder with your templates and run `tera` if a template changes. For this to work, it is recommended to\nname you template as `foobar.md.tera` if your template expands into a markdown file for instance.\nYou may then use [fswatch](https://github.com/emcrisostomo/fswatch) and watch a `templates` folder using:\n\n    fswatch templates -e \".*\\.md$\" | \\\n        xargs -n1 -I{} \\\n        tera --include-path templates \\\n            --template templates/template.md.tera context.json\n\n## Execute as Docker container\n\nYou can find a `tera` Docker image at `chevdor/tera`. The image is very small and should be less than 8MB.\n\nYou can test it with:\n\n    docker run --rm -it chevdor/tera --version\n\nThe Docker image mentioned above is not yet built by the CI so you may not find the very latest version from time to time.\n\n### Build container image\n\n    docker build --tag tera-cli .\n\n### Execute `tera` from the Docker container\n\n**Check the tera help**\n\n    docker run -it --rm tera-cli --help\n\n**Parse a template**\n\n    docker run -it --rm \\\n        --volume=\"$(pwd)/templates:/templates\" \\\n        --read-only \\\n        --env=FOO=BAR \\\n        tera-cli --template /templates/env-debug.txt --env-only --env-key env\n\n## What can I do with that anyway ?\n\nWell…​ if you have **data** and you want to format them, this tool will likely be a great companion.\n\n-   You may generate beautiful changelogs in markdown, asciidoc, restructured text, etc…​\n\n-   You may generate some more human views of your data\n\n-   You may…​ make a blog with that…​\n\n-   You may generate k8s config files…​.\n\n## Features\n\n### Supported formats\n\nYou may pass the `context` data either as file of into **stdin**.\n\nCurrent **stdin** supports only json.\n\n### ENV support\n\nThere are several options related to the environment variables.\n\n#### Enable ENV variables injection\n\nBy default, the environments variables are not merged in. You can turn this feature on with `--env`.\n\n#### Collisions\n\nNow that you enabled the merging of the ENV variables, it is important to understand that, in some cases, your ENV may collide with your context data. This can be convenient if you want your ENV to override the context data.\n\n#### ENV injection priority\n\nIf you prefer the context data to overwrite the ENV, you may use `--env-first`. As a result, the ENV will be applied first to the context and your context data will be loaded afterward.\n\n#### Collisions handling\n\nYou may perfer to consider collisions as failures. This is what `--fail-on-collision` is for. If a collision is detected, the program will exit with a status code of `1` and an appropriate message.\n\n#### ENV only\n\nYou may also want to ONLY load ENV variables as context data. This is what `--env-only` does.\n\n#### ENV sub key\n\nBy default, your ENV variables will be loaded at the root of the context data. For instance, the `HOME` ENV variable will be then available in your tera template as `{{ HOME }}`. As we just mentioned, collisions may be an issue. There is an easy to prevent them entirely: you may move the ENV into a sub key in the context data. This is allowed thanks to the `--env-key \u003cname\u003e` option. For instance, using `--env-key env` will make your `HOME` ENV variable available in the tera template as `{{ env.HOME }}`.\n\nWhile the syntax is a little more verbose, paired with `--fail-on-collision`, this option allows ensuring that nothing happens in your back.\n\n### External files\n\nUsing the `--include` flag, the command will scan recursively for files that could be [included](https://tera.netlify.app/docs/#include), used as [macros](https://tera.netlify.app/docs/#macros) or for [inheritance](https://tera.netlify.app/docs/#inheritance). By default, it will scan the folder where the main template is located, unless the `--include-path` option is given.\n\nFrom this repository, you can test the **include** feature with the command:\n\n    USER=\"[YOURNAME]\" tera --template data/include/hello.txt --include --env-only\n\nand test the **inheritance** feature with:\n\n    USER=\"[YOURNAME]\" tera --template data/inheritance/child.txt --inherit --env-only\n\n### Content escaping\n\nPassing the `-a | --escape` flag allows escaping the content.\n\n## Usage\n\n    Command line utility for the tera templating engine. You need to provide a template using the tera syntax as well as some data (various format are supported)\n\n    Usage: tera [OPTIONS] --template \u003cTEMPLATE\u003e [CONTEXT]\n\n    Arguments:\n      [CONTEXT]  Location of the context data. This file can be of the following type: json | toml | yaml. If you prefer to pass the data as stdin, use `--stdin`\n\n    Options:\n      -t, --template \u003cTEMPLATE\u003e          Location of the template\n      -i, --include                      This flag tells the command to parse all templates found in the same path where the given template is located [aliases: inherit]\n          --include-path \u003cINCLUDE_PATH\u003e  Option to define a different path from which search and parse templates [aliases: inherit-path]\n      -s, --stdin                        The context data can be passed using stdin\n      -e, --env                          If true, the current ENV will be appended to the data under the --env-key key\n          --env-key \u003cENV_KEY\u003e            By default, if --env is set, the environment variables will be attached at the root of the context. This is convenient but may end up conflicting with your data. To prevent collisions, you can provide a custom key with this option\n          --env-first                    By default, the context is made of the data you pass and the ENV is applied afterwards. Setting this option will apply the ENV first. This is interesting if you prefer your data to override the ENV\n          --fail-on-collision            if you prefer your data to override the ENV\n          --env-only                     If you want to solely use the ENV as context, you may pass this option. This will prevent an error about no context being passed to be raised\n      -o, --out \u003cOUT\u003e                    Optional output file. If not passed, using stdout\n      -a, --escape                       Auto-escape rendered content. This is useful for HTML output\n      -h, --help                         Print help\n      -V, --version                      Print version\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchevdor%2Ftera-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchevdor%2Ftera-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchevdor%2Ftera-cli/lists"}