tplenv
tplenv renders placeholders in template files.
{{VARNAME}},$VARNAME, and${VARNAME}read from environment variables (or fromenvironment.VARNAMEwith--value-file-only).{{ .Values.key }}reads from a YAML values file.
Install
To install tplenv on your computer, just run:
Building
Binary path:
Help
Show CLI usage:
Usage
| )
Options:
-f, --file <PATH>: input template file (required)--file-pattern <PATTERN>: match multiple input files by filename pattern (supports*and<NUM>, e.g.<NUM>-*.yaml)--values-file <PATH>: values YAML file (default:Values.yaml, alias:--values)-o, --output <PATH>: output file (-or omitted means stdout)-v, --verbose: print substitutions to stderr--create-values-file: ask for missing placeholders and write/update the values file ($VAR/${VAR}are stored asenvironment.VAR)- In this mode,
environment.VARfrom the values file has priority over OS environment variables.
- In this mode,
--force: only valid with--create-values-file; asks for all.Values.*placeholders and uses existing values as prompt defaults--value-file-only: resolve{{VARNAME}}fromenvironment.VARNAMEin the values file (do not read OS environment variables)--eval: only with--create-values-file; print prompted keys as bashexportlines (useful witheval "$( ... )")- If
--output <FILE>is also set, the rendered YAML is still written to that file while exports are printed to stdout.
- If
--indent: when a replacement value contains multiple lines, tplenv emits YAML block scalars automatically (|or|+for trailing empty lines) and keeps indentation valid-h, --help: print help--version: print version
Notes:
- Use either
--fileor--file-pattern. - With multiple matched files, output is a YAML multi-document stream (
---separators), to stdout or to--output <FILE>. - Multi-file mode fails unless all matched input files end with
.yaml.
Examples
Render using environment variables and values file:
Create/update only missing values in Values.yaml, then render:
Ask for all values found in the template and prefill from existing file values:
Resolve {{VARNAME}} from the values file:
With --value-file-only, interactive mode also manages missing environment.* keys:
Process all numbered YAML files in a directory:
Generate bash exports from prompted values:
With --force, all prompted keys are exported (for example image.tag -> IMAGE_TAG, environment.APP_NAME -> APP_NAME).
Keep multiline values aligned:
More runnable examples are in examples/README.md.
That includes a --value-file-only --create-values-file --force interactive example with defaults.
Tests
Run unit tests:
Nix (Deterministic Build)
This repo now includes a flake-based build:
/Users/christoffetzer/Library/Mobile Documents/com~apple~CloudDocs/GIT/scontainug/tplenv/flake.nix/Users/christoffetzer/Library/Mobile Documents/com~apple~CloudDocs/GIT/scontainug/tplenv/default.nix
Build with Nix:
Enter development shell:
For deterministic builds across machines, commit flake.lock to the repo.
If it does not exist yet, generate it once with: