/tmplx

tmplx is a simple template renderer based on the Go template engine. It is designed to be used in a shell pipeline. It reads a template from disk, parses it, reads data from env, json file or yaml file, and renders the template to stdout (dry-run) or to a file.

Primary LanguageGoGNU General Public License v3.0GPL-3.0

tmplx

tmplx is a simple template renderer based on the Go template engine. It is designed to be used in a shell pipeline. It reads a template from disk, parses it, reads data from env, json file or yaml file, and renders the template to stdout (dry-run) or to a file.

Installation

We provide pre-built binaries for Linux, MacOS and Windows. You can download them from the releases page. Alternatively, you can build the binary yourself using the build instructions, using the Docker image or using Go directly:

Go

go install github.com/leonsteinhaeuser/tmplx@latest

Docker

You can also use the Docker image to run tmplx. The image is based on gcr.io/distroless/static and is only a few MB in size.

Build

To build the binary yourself, you need to have Go installed. Then, clone the repository and run go build -o tmplx . in the root directory of the repository.

Usage

Short Flag Long Short Type Default Description
-d --dry-run bool If set, the output will not be written to the output file.
-f --format string The format of the template data. Valid values are: env, json, yaml. (default "env")
-h --help help for tmpls
-o --output string The path to the output file. (default "output.txt")
-s --source string The path to the source file containing template data. Valid values are: .<json yaml>. If format is env, this flag caries the
-t --template string The path to the template file. (default "template.tmpl")
-l --delim-left string {{ The left delimiter for the template engine.
-r --delim-right string }} The right delimiter for the template engine.
-v --version version for tmpls

Example

The following example shows how to use tmplx to render a template using data from environment variables.

Setup environment variables

export TMPLX_USER_ACCOUNT_0="user0:pass0"
export TMPLX_USER_ACCOUNT_1="user1:pass1"
export TMPLX_USER_ACCOUNT_2="user2:pass2"
export TMPLX_USER_ACCOUNT_3="user3:pass3"
export TMPLX_USER_ACCOUNT_4="user4:pass4"
export TMPLX_USER_ACCOUNT_5="user5:pass5"
export TMPLX_USER_ACCOUNT_6="user6:pass6"
export TMPLX_USER_ACCOUNT_7="user7:pass7"
export TMPLX_USER_ACCOUNT_8="user8:pass8"
export TMPLX_USER_ACCOUNT_9="user9:pass9"
export TMPLX_USER_ACCOUNT_10="user10:pass10"

Execute tmplx

tmplx -t _tests/template.tmpl --dry-run

With custom delim:

go run main.go -t _tests/custom_delim.tmpl --dry-run -l '{|' -r '|}'