Skip to content

Minimal project used to handle placeholders in files

License

Notifications You must be signed in to change notification settings

pyaillet/placeholder

Repository files navigation

placeholder

Build Status codecov

Minimal project used to handle placeholders in files

Description

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.

Usage examples

With json

$ 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

With yaml

$ 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

With properties

$ 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

From environment

$ 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

Bloc separator

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

Build it

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