README ¶
tpl
Render yaml and json with go templates from the command line.
The templates are executed with the text/template package. This means they come with the additional risks and benefits the text templates provide. Additionally, Sprig functions are available.
Usage
The input data is read from stdin via pipe or redirection.
# Redirection
tpl < path/to/input.json
# Pipe
curl localhost | tpl
The template is either read from the first positional argument or from a path specified via --template
or -t
flag.
# Positional argument
echo '{"place": "bar"}' | tpl 'lets go to the {{.place}}!'
# File
echo '{"place": "bar"}' | tpl --template path/to/template
Flags
-n
-no-newline
do not print a new line at the end
-t string
-template string
alternative way to specify template
Installation
Go
go install github.com/bluebrown/tpl
Docker
curl -s https://jsonplaceholder.typicode.com/users/1 | docker run -i bluebrown/tpl '{{.name}}'
Example
$ curl -s https://jsonplaceholder.typicode.com/users | tpl '<table>
<caption>My Address Nook</caption>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
</tr>
{{- range . }}
<tr>
<th>{{ .name }}</th>
<td>{{ .email }}</td>
<td>{{ .phone }}</td>
<td>
<ul>
{{- range $key, $val := .address }} {{ if ne $key "geo" }}
<li><strong>{{$key}}:</strong> {{$val}}</li>
{{- end -}}
{{ end }}
</ul>
</td>
</tr>
{{- end -}}
</table>' | less
The result looks like this
Name | Phone | Address | |
---|---|---|---|
Leanne Graham | Sincere@april.biz | 1-770-736-8031 x56442 |
|
Ervin Howell | Shanna@melissa.tv | 010-692-6593 x09125 |
|
Clementine Bauch | Nathan@yesenia.net | 1-463-123-4447 |
|
Patricia Lebsack | Julianne.OConner@kory.org | 493-170-9623 x156 |
|
Chelsey Dietrich | Lucio_Hettinger@annie.ca | (254)954-1289 |
|
Mrs. Dennis Schulist | Karley_Dach@jasper.info | 1-477-935-8478 x6430 |
|
Kurtis Weissnat | Telly.Hoeger@billy.biz | 210.067.6132 |
|
Nicholas Runolfsdottir V | Sherwood@rosamond.me | 586.493.6943 x140 |
|
Glenna Reichert | Chaim_McDermott@dana.io | (775)976-6794 x41206 |
|
Clementina DuBuque | Rey.Padberg@karina.biz | 024-648-3804 |
|
Documentation ¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.