Skip to content

A tool to apply variables from cli, env, JSON/TOML/YAML files to templates

License

Notifications You must be signed in to change notification settings

krakozaure/tmpl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tmpl

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.

Project status

This project is in a very early stage. Things might break !

Usage

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

Configuration

No configuration needed. Everything is done on the command line.