Render golang template with command line.
templates folder has some example templates.
Download gotmpl from release, and put it in your PATH.
Or build from source
go get github.com/NateScarlet/gotmpl/cmd/gotmpl
Render template to stdout
gotmpl ./template.gotmpl
Render template with data
gotmpl Key=Value ./template.gotmpl
Render template that file name has =
in it.
gotmpl =./template=.gotmpl
Render to a file.
gotmpl -o ./output.txt ./template.gotmpl
Render multiple template to stdout.
first template executed, others can be used with template
action.
gotmpl Key=Value ./template.gotmpl ./template2.gotmpl
Read data from stdin
echo '{"Key": "Value"}' | gotmpl -i - ./template.gotmpl
Read data from file
gotmpl -i data.json ./template.gotmpl
- sprig functions
cwd
() current working directory.args
() return command line argument list.templateFiles
() return template file list.__file__
() value of-o
option, empty string if not specified.absPath
(string) convert path to absolute.lowerFirst
(string) lower first rune of stringupperFirst
(string) upper first rune of string
The "." object is a map[string]interface{}
, so you can use set
function to modify it.
There are some default data for convenient:
Name
:index (__file__ | absPath | base | split ".") 0
if__file__
not emptyPackage
__file__ | absPath | dir | base
if__file__
not empty
Data merged in order:
- default data
-i
file data- inline key value pair