tplenv 0.7.0

Render template placeholders from environment variables and YAML values files
tplenv-0.7.0 is not a library.

tplenv

tplenv renders placeholders in template files.

  • {{VARNAME}}, $VARNAME, and ${VARNAME} read from environment variables (or from environment.VARNAME with --value-file-only).
  • {{ .Values.key }} reads from a YAML values file.

Install

To install tplenv on your computer, just run:

cargo install --path .

Building

cargo build --release

Binary path:

./target/release/tplenv

Help

Show CLI usage:

tplenv --help

Usage

tplenv (--file INPUT.yaml | --file-pattern "<NUM>-*.yaml") [--values-file Values.yaml] [--output OUTPUT.yaml] [--value-file-only]

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 as environment.VAR)
    • In this mode, environment.VAR from the values file has priority over OS environment variables.
  • --force: only valid with --create-values-file; asks for all .Values.* placeholders and uses existing values as prompt defaults
  • --value-file-only: resolve {{VARNAME}} from environment.VARNAME in the values file (do not read OS environment variables)
  • --eval: only with --create-values-file; print prompted keys as bash export lines (useful with eval "$( ... )")
    • If --output <FILE> is also set, the rendered YAML is still written to that file while exports are printed to stdout.
  • --indent: when a replacement value contains multiple lines, tplenv emits YAML block scalars automatically (| or |+ for trailing empty lines) and keeps indentation valid
  • --context: with --create-values-file, show context before each question
    • default behavior prints only the line containing the variable
    • with --context, tplenv prints the full paragraph if it contains only that variable; otherwise it prints the matching list entry (- ... or numbered item)
  • -h, --help: print help
  • --version: print version

Notes:

  • Use either --file or --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:

tplenv --file deployment.tpl.yaml --values-file Values.yaml --output deployment.yaml

Create/update only missing values in Values.yaml, then render:

tplenv --file deployment.tpl.yaml --create-values-file

Ask for all values found in the template and prefill from existing file values:

tplenv --file deployment.tpl.yaml --create-values-file --force

Resolve {{VARNAME}} from the values file:

tplenv --file deployment.tpl.yaml --values-file Values.yaml --value-file-only

With --value-file-only, interactive mode also manages missing environment.* keys:

tplenv --file deployment.tpl.yaml --values-file Values.yaml --value-file-only --create-values-file

Process all numbered YAML files in a directory:

tplenv --file-pattern "examples/06-file-pattern/<NUM>-*.yaml" --values-file examples/06-file-pattern/Values.yaml --value-file-only

Generate bash exports from prompted values:

eval "$(tplenv --file deployment.tpl.yaml --create-values-file --eval)"

With --force, all prompted keys are exported (for example image.tag -> IMAGE_TAG, environment.APP_NAME -> APP_NAME).

Keep multiline values aligned:

tplenv --file deployment.tpl.yaml --values-file Values.yaml --indent

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:

cargo test

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:

nix build .#tplenv

Enter development shell:

nix develop

For deterministic builds across machines, commit flake.lock to the repo. If it does not exist yet, generate it once with:

nix flake lock

Shell Completion

This repo includes completion files for Bash and Zsh:

  • /Users/christoffetzer/Library/Mobile Documents/com~apple~CloudDocs/GIT/scontainug/tplenv/completions/tplenv.bash
  • /Users/christoffetzer/Library/Mobile Documents/com~apple~CloudDocs/GIT/scontainug/tplenv/completions/_tplenv

Install completion directly via tplenv:

tplenv --install-completion

Pick a shell explicitly:

tplenv --install-completion bash
tplenv --install-completion zsh

Alternative helper script (same behavior):

./scripts/install-completion.sh