gotmpl

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 11 Imported by: 0

README

gotmpl

A CLI tool for templating files using input data from a json file. Gotmpl features the Sprig functions for richer templating. You can find the function documentation at http://masterminds.github.io/sprig/.

$ gotmpl -h
usage: gotmpl [option] [values_json] file_to_template
If values_json is omitted, values are read from stdin (as json)
Sprig functions are supported, see https://masterminds.github.io/sprig/
gotmpl also supports the following aditional function(s):
shellescape string (returns string)
Flags:
  -o string
        output file, default is stdout

$ echo '{"hello":"world"}' > values.json

$ echo 'Hello {{ .hello }}' > file_to_template

$ gotmpl values.json file_to_template 
Hello world

$ gotmpl -o output values.json file_to_template

You can also use environment variables as template values via the Sprig env function and mix with values from values.json.

$ export MY_ENV_VAR=world

$ echo 'Hello {{ env "MY_ENV_VAR" }}' > file_to_template

$ echo '{}' | gotmpl file_to_template
Hello world

The shellescape function can be used to escape arguments for shell scripts, e.g:

$ echo '{"name":"Eugene Belford;RM -RF /"}' > values.json

$ echo 'Hello {{ .name }}, type the following in a terminal: `echo {{ .name | shellescape }}`' > file_to_template

$ gotmpl values.json file_to_template
Hello username;RM -RF, type the following in a terminal: `echo 'username;RM -RF'`

Building and installing

Please use Go 1.21.2 or later...

go install github.com/sa6mwa/gotmpl@latest

# or use the Makefile...

make install

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL