Minimal project used to handle placeholders in files
The goal of this project is to provide a simple tool to replace placeholders
in files with values either from json, yaml, property files or from the
environment.
A placeholder is made from a prefix, a suffix and a key identifier matching
this regex: [A-Za-z][A-Za-z0-9_]*
.
It's also possible to list keys identified in one or more files by using the
command: placeholder -s '{{' -e '}}' list *.templates
.
When a key is identified but no corresponding value is provided the program exits with an error.
$ cat template.file
This is a simple template file containing a <KEY> placeholder surrounded with
'${' and '}' which will be replaced by the value contained in a value file.
The key value is ${KEY}
$ cat values.json
{
"KEY": "value from json"
}
$ placeholder replace -i values.json template.file
$ cat template.file
This is a simple template file containing a <KEY> placeholder surrounded with
'${' and '}' which will be replaced by the value contained in a value file.
The key value is value from json
$ cat values.yaml
KEY: value from yaml
$ placeholder replace -i values.yaml template.file
$ cat template.file
This is a simple template file containing a <KEY> placeholder surrounded with
'${' and '}' which will be replaced by the value contained in a value file.
The key value is value from yaml
$ cat values.properties
KEY=value from properties
$ placeholder replace -i values.properties template.file
$ cat template.file
This is a simple template file containing a <KEY> placeholder surrounded with
'${' and '}' which will be replaced by the value contained in a value file.
The key value is value from properties
$ KEY="value from env" placeholder replace template.file
$ cat template.file
This is a simple template file containing a <KEY> placeholder surrounded with
'${' and '}' which will be replaced by the value contained in a value file.
The key value is value from env
You can also change the default bloc separator by specifying the start and end bloc with the -s
and -e
arguments :
$ placeholder -s '%#' -e '#%' replace -i values.json template.file
$ cat template.file
This is a simple template file containing a <KEY> placeholder surrounded with
'%#' and '#%' which will be replaced by the value contained in a value file.
The key value is value from env
To build this project, you must have make and go >= 1.12 installed.
You can then just type:
make build
If you don't want to install go but use docker instead, type:
make docker-build