yemplate
is a simple CLI wrapper around golang’s text/template library. It
is inspired by Helm.
It takes the following inputs:
- A file that contains text/template markups
- An optional yaml file with defining parameters (
-f
) - Optional parameters that might override the parameters of the yaml file
(
--set
)
Execute the following command:
go get github.com/origoss/yemplate
The text1.txt
template file looks like this:
Welcome {{ .name }}, I know your favorite food is {{ .favoriteFood }}.
To execute a simple substitution:
yemplate text1.txt --set name=Gergely,favoriteFood=chocolate
Welcome Gergely, I know your favorite food is chocolate.
The param1.yaml
file looks like this:
name: Gergely
favoriteFood: chocolate
To execute the substitution:
yemplate text1.txt -f param1.yaml
Welcome Gergely, I know your favorite food is chocolate.
You can override the parameters defined in the file with the command-line parameters:
yemplate text1.txt -f param1.yaml --set favoriteFood=hamburger
Welcome Gergely, I know your favorite food is hamburger.
The param2.yaml
file looks like this:
name: Gergely
favoriteFoods:
- chocolate
- banana
- ice cream
The text2.txt
file looks like this:
Welcome {{ .name }}, I know your favorite foods are
{{ range .favoriteFoods -}}
-{{ . }}
{{ end -}}
To execute the substitution:
yemplate text2.txt -f param2.yaml
Welcome Gergely, I know your favorite foods are -chocolate -banana -ice cream
Or you can try setting the parameters via the CLI:
yemplate text2.txt \
--set "name=Kinga" \
--set "favoriteFoods[0]=pizza" \
--set "favoriteFoods[1]=hamburger"
Welcome Kinga, I know your favorite foods are -pizza -hamburger