tmpl
allows to apply variables from JSON/TOML/YAML files,
environment variables or CLI arguments to template files using Golang
text/template
and functions from the Sprig project.
This project is in a very early stage. Things might break !
For simplicity, everything is output on stdout
. To write the result in a
file, use shell redirection.
If a variable is not found and the strict mode is disabled (default disabled), each missing value will be replaced with an empty string.
- Print help/usage message.
# $ tmpl
# $ tmpl -h
$ tmpl --help
USAGE: tmpl [OPTIONS] INPUT
INPUT is a template file or '-' for stdin
OPTIONS:
-f value
load variables from JSON/TOML/YAML files (format: file path)
-s exit on any error during template processing (default false)
-v value
use one or more variables from the command line (format: name=value)
stdin
and environment variables.
$ echo 'Editor = {{ env "EDITOR" }}, Shell = {{ env "SHELL" }}' | tmpl -
Editor = nvim, Shell = /bin/bash
stdin
and CLI variables.
$ tmpl -v foo=bar - <<< 'Hello, {{ .foo }} !'
Hello, bar !
- Sample from this repository
Output is not pasted here because of its length.
$ tmpl -f ./stores/data.yaml ./inputs/sample.txt.tmpl
No configuration needed. Everything is done on the command line.