3 unstable releases
0.1.1 | Nov 20, 2023 |
---|---|
0.1.0 | Nov 20, 2023 |
0.0.1 | Nov 20, 2023 |
#1303 in Command line utilities
79KB
304 lines
TPP (Tera Pre-Processor)
tpp
(Tera Pre-Processor) is a versatile CLI (Command Line Interface) tool crafted for preprocessing files using the
Tera templating engine. Drawing inspiration from renowned pre-processors like cpp
and gpp, tpp
stands out with its user-friendly command-line interface that
efficiently renders templates for diverse applications.
Learn more about Tera
Example
Create a Dockerfile
from a template:
Dockerfile.in
FROM {{ base_image }}
LABEL maintainer="{{ maintainer }}"
RUN apt-get update && apt-get install -y \
{{ packages | join(' ') }}
COPY . /app
WORKDIR /app
ENV PORT {{ port }}
EXPOSE {{ port }}
CMD ["{{ entrypoint }}"]
context.json
{
"base_image": "python:3.8-slim",
"maintainer": "dev@example.com",
"packages": [
"build-essential",
"libpq-dev"
],
"port": 8080,
"entrypoint": "python app.py"
}
Command
tpp Dockerfile.in -c context.json -o Dockerfile
Dockerfile
FROM python:3.8-slim
LABEL maintainer="dev@example.com"
RUN apt-get update && apt-get install -y \
build-essential libpq-dev
COPY . /app
WORKDIR /app
ENV PORT 8080
EXPOSE 8080
CMD ["python app.py"]
Usage
Usage: tpp [OPTIONS] <TEMPLATE_FILE>
Arguments:
<TEMPLATE_FILE> Path to the template file you wish to render
Options:
-c, --context-file <CONTEXT_FILE> Optional: Specify the path to context data in JSON, YAML, or TOML format
--stdin Optional: Enable passing context data via standard input. Useful for merging different context files or processing context data with tools like `jq`
-i, --include <INCLUDE> Optional: Define directories (and their subdirectories) to search for additional templates referenced in `<TEMPLATE_FILE>`. Necessary for templates that import or include other files. Note: any relative paths specified in the `import` or `include` statements within templates are resolved relative to the directories indicated by `--include`
--env Optional: Use current environment variables as context data. This can be merged with data from `--context-file` or `--stdin`. Merging occurs after, unless `--env-first` is set. Useful for dynamic template data population
-e, --env-key <ENV_KEY> Optional: Designate a specific key under which all environment variables will be nested in the context data. Requires `--env` to be set
--env-first Optional: Apply environment variable context before any other context. Allows another context to override the env context. Requires `--env` to be set
--fail-on-collision Optional: Command will terminate if there's a conflict between environment variables and other context data. Requires `--env` to be set
-o, --out <OUT> Optional: Specify an output file to write the rendered template. If omitted, the output is directed to standard output (stdout)
--escape Optional: Enable auto-escaping of rendered content, which is particularly useful for HTML
--debug Optional: Enable debug mode to print detailed debug information to standard output (stdout)
-h, --help Print help
-V, --version Print version
Dependencies
~14–24MB
~354K SLoC