https://github.com/diginc/jinja-recurse
Jinja Recursive Templating for the CLI
https://github.com/diginc/jinja-recurse
cli hacktoberfest jinja template
Last synced: 8 months ago
JSON representation
Jinja Recursive Templating for the CLI
- Host: GitHub
- URL: https://github.com/diginc/jinja-recurse
- Owner: diginc
- License: mit
- Created: 2020-03-04T04:23:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-26T21:40:17.000Z (over 3 years ago)
- Last Synced: 2025-09-25T14:56:23.851Z (9 months ago)
- Topics: cli, hacktoberfest, jinja, template
- Language: Python
- Homepage:
- Size: 75.2 KB
- Stars: 1
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jinjarecurse CLI tool
_________________




_________________
Jinja Recursive Templating for the CLI. Recursively template one file or many
folders of many files like a config management languages allow, without the
whole config management language. Useful if you're switching from managing an
application from config management to just docker and need some simple
templating logic.
## Installation
```
pip install jinjarecurse
```
## Example Usage
```
$ jinjarecurse --help
jinjarecurse (CLI)
Usage:
jinjarecurse --vars=VARS_FILE --input=INPUT_PATH --output=OUTPUT_PATH
Options:
-v , --vars
-i , --input
-o , --output
```
### Single file
Given a config file containing your variables e.g. `vars.yaml`:
```
#comment: not available
root: /
number: 1
dictionary:
street: 123 North Ave
city: New York
state: New York
list:
- ABC
- DEF
- HJK
layer_1:
layer_2:
layer_3: last
```
And an input file jinja2 template e.g. `i_file`:
```
# Top level
{{root}}
{{number}}
{{dictionary}}
{{list}}
{{layer_1}}
# Nested data
{{dictionary.street}}
{{dictionary.city}}
{{dictionary.state}}
{{layer_1.layer_2.layer_3}}
```
You can populate it and specify an output filepath e.g. `o_file`:
```
$ jinjarecurse -v example/vars.yaml -i example/i_file -o example/o_file
WARNING: example/o_file (output) exists and any conflicting files will be overwritten
Writing from example/i_file to example/o_file
```
Contents of the output file e.g. `o_file`:
```
# Top level
/
1
{'street': '123 North Ave', 'city': 'New York', 'state': 'New York'}
['ABC', 'DEF', 'HJK']
{'layer_2': {'layer_3': 'last'}}
# Nested data
123 North Ave
New York
New York
last
```
### Directory
You can also template an entire directory e.g. `i_dir` at once. Note the
output files in the output directory will maintain the filenames from the
input directory:
```
$ jinjarecurse -v example/vars.yaml -i example/i_dir -o example/o_dir
Writing from example/i_dir/i_file to example/o_dir/i_file
Writing from example/i_dir/i_file_1 to example/o_dir/i_file_1
Writing from example/i_dir/i_file_2 to example/o_dir/i_file_2
```
## Tests
To run the unit tests, first install the dependencies:
```
$ pipenv install --dev .
```
Then invoke pytest:
```
$ pipenv run py.test -vvvs
```
## Changelog
Please see the [Releases](https://github.com/diginc/Jinja-Recurse/releases)
and [CHANGELOG.md](https://github.com/diginc/Jinja-Recurse/blob/master/CHANGELOG.md).