Automatic replace variables in configuration file templates from environment variables.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
debian
src
.editorconfig
.env.dist
.env.in
.gitignore
CMakeLists.txt
README.md
Vagrantfile_jessie
Vagrantfile_stretch
parameters.code-workspace

README.md

Parameters

Automatic replace variables in configuration file templates from environment variables.

The parameters program takes an input file template and a given regular expression for searching environment variables. The variables in the template file will be replaced by the values of found environment variables by the exact same name.

Examples

Simple example

First set the environment variables. This can also come from GitLab CI variables:

export SYMF_DB_USER=my_user
export SYMF_DB_PASS=my_super_secret_password

Then set up a dotenv template file (.env.dist):

DB_USER=@SYMF_DB_USER@
DB_PASS=@SYMF_DB_PASS@

Now parameters will replace the variables:

parameters --input .env.dist --regexp ^SYMF_ > .env

This will take .env.dist as input file and ^SYMF_ as regular expression to search for variables in your shell environment. Searching the environment variables by a given regular expression is the same as running env | grep ^SYMF_ in your shell.

The result in .env file:

DB_USER=my_user
DB_PASS=my_super_secret_password

Example using different envrionments

You can also use different environments like Testing, Staging, Production, etc.

parameters --input .env.dist --regexp ^SYMF_ --env testing > .env

testing will be converted to TESTING.

Example using different instances

parameters --input .env.dist --regexp ^SYMF_ --instance shopa > .env

shopa will be converted to SHOPA.

Also a combination is possible.

parameters --input .env.dist --regexp ^SYMF_ --env testing --instance shopa > .env

Run parameters --help to see more parameters.

Dependencies

  • cmake
  • Boost

Optional:

Install dependencies on macOS

brew install boost

Install dependencies on Debian 9

sudo apt-get install --no-install-recommends libboost-filesystem-dev libboost-program-options-dev

Build from Source

This will build the binary.

./bin/build.sh

Then the binary is available in build_release/bin.

After building the project, run:

./bin/install.sh

Install via Debian repository

Only Debian 9 (stretch) is supported.

Add the public GPG key to the apt sources keyring:

wget -qO - https://fox21.at/christian_mayer.asc | sudo apt-key add -

Verify key on the keyring. This should print out informations about the key:

apt-key list 2814B4288C4594FF0BA75571F96ED997C9382D47

Add apt source file and update:

echo 'deb https://debian.fox21.at/ stretch main' > /etc/apt/sources.list.d/fox21at.list
apt-get update

Install the package:

sudo apt-get install parameters

Now you can run the program:

parameters --help

Install under Debian via .deb file

wget -O parameters.deb https://github.com/TheFox/parameters/releases/download/v1.0.0-rc.2/parameters_1.0.0-rc.2_amd64.deb
sudo dpkg --install parameters.deb

Install via Homebrew

  1. Add the thefox/brewery tap to brew.

    brew tap thefox/brewery
    
  2. Actual installation

    brew install parameters
    

Tested under

  • macOS 10.13 High Sierra
  • macOS 10.14 Mojave
  • Debian 8 (jessie)
  • Debian 9 (stretch)