Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thecodesmith/j2
Minimalist Jinja2 CLI
https://github.com/thecodesmith/j2
Last synced: 23 days ago
JSON representation
Minimalist Jinja2 CLI
- Host: GitHub
- URL: https://github.com/thecodesmith/j2
- Owner: thecodesmith
- Created: 2019-08-12T16:07:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-11T19:04:38.000Z (12 months ago)
- Last Synced: 2024-11-01T20:52:13.723Z (about 2 months ago)
- Language: Python
- Size: 61.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
Awesome Lists containing this project
README
# J2 - the minimalist Jinja2 CLI
## Inspiration
I wanted a simple CLI for Jinja2 that operated similarly to Helm:
* Render a template from a file
* Pass custom values from a yaml file
* Override custom values directly on the command line
* Allow custom filters to be provided from a fileThis CLI aims to provide these features in the simplest way possible.
## Usage
❯ j2 --help
a minimalist Jinja2 CLIusage: j2 [-h] [--values [value.yaml]] [--set my.value=42]
templatepositional arguments:
template Template file to processoptional arguments:
-h, --help show this help message and exit
--values [value.yaml]
Input values file path; "-" to use stdin
--filters [filters.py]
Custom Jinja2 filters from Python file. Loads all
top-level functions and registers them as filters.
--set my.value=42 Set values on the command line. Can be used multiple
times.## Docker
The `j2` CLI is available as a Docker image hosted on Docker Hub:
https://hub.docker.com/r/thecodesmith/j2.Run `j2` locally in Docker with an alias like this:
alias j2='docker run -it --rm -w /app -v $PWD:/app thecodesmith/j2 j2'
## Examples
Basic usage:
j2 manifest.j2 --values values.yaml > manifest.yaml
With custom values overridden on the command line:
j2 manifest.j2 --values values.yaml --set app.namespace=foo > manifest.yaml
With custom filters defined in a file:
j2 manifest.j2 --filters filters.py > manifest.yaml
Where the filters file looks like this:
```python
def parentheses(value):
""" Usage: {{ var | parentheses }} """
return '(' + value + ')'
```