Skip to content

Simple text templating utility based on the golang text/template library

License

Notifications You must be signed in to change notification settings

origoss/yemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

1 Introduction

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)

2 Installation

Execute the following command:

go get github.com/origoss/yemplate

3 Examples

3.1 Simple substitution

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.

3.2 Simple substitution with parameters file

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.

3.3 A bit more complex example

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 

About

Simple text templating utility based on the golang text/template library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages