/tempura

A Fast and Flexible Template Fill CLI Tool.

Primary LanguageGoMIT LicenseMIT

tempura

A Fast and Flexible Template Fill CLI Tool.

codecov

Enter the following information to output the text that fills the template.

  • a template written in the format text/template
  • variables by JSON

Install

go install

go install github.com/korosuke613/tempura@latest

docker

docker pull ghcr.io/korosuke613/tempura

manual

Download from Releases.

Getting Started

using binary

❯ tempura --input-string '{"Name": "John", "Message": "Good"}' --template-string 'Hello {{.Name}}, {{.Message}}'
Hello John, Good

or using docker

❯ docker run --rm ghcr.io/korosuke613/tempura --input-string '{"Name": "John", "Message": "Good"}' --template-string 'Hello {{.Name}}, {{.Message}}'
Hello John, Good

Example

input multiline template

❯ tempura \
 --input-string '{"Name": "John", "Message": "Good"}' \
 --template-string \
'Hello {{.Name}},
{{.Message}}'
Hello John,
Good

read template and inputs

input

input.json

{
  "Name": "John",
  "Message": "Good"
}

template.tmpl

Hello {{.Name}},
{{.Message}}

output

❯ tempura -i input.json -t template.tmpl
Hello John,
Good

output to file

❯ tempura -o ./output.txt
❯ cat ./output.txt
Hello John,
Good

use Actions

https://golang.org/pkg/text/template/#hdr-Actions

input

input.json

{
  "isTrue": true,
  "Cat": "cat"
}

template.tmpl

{{if .isTrue}}isTrue is True!{{end}}

{{if .isFalse}}never{{else}}isFalse is False!{{end}}

{{if eq .Cat "cat"}}Cat: nyan{{end}}

output

❯ tempura
isTrue is True!

isFalse is False!

Cat: nyan

Options

❯ tempura -h
A Fast and Flexible Template Fill CLI Tool built with love by korosuke613 in Go.

Usage:
  tempura [flags]

Flags:
  -h, --help                       help for tempura
  -i, --input-filepath string      input file name (default "input.json")
      --input-string string        input string
  -o, --output string              output file name
  -t, --template-filepath string   template file name (default "template.tmpl")
      --template-string string     template string
  -v, --version                    show version