Jinja Recursive Templating from the CLI
Project description
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 <file>, --vars <file>
-i <file>, --input <file>
-o <file>, --output <file>
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 and CHANGELOG.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jinjarecurse-0.0.2.tar.gz
.
File metadata
- Download URL: jinjarecurse-0.0.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0427f57ccc62f7ed2ccb33d2f851c2fc2a7ce483878e93ffd1714d8d2af23fb8 |
|
MD5 | ee08a29ee4c5add01b4923f1e6e09473 |
|
BLAKE2b-256 | c6a71e7785f66a6d7afe65df9a4c895d0c303b2c411fd1978eabc988e54cdd44 |
File details
Details for the file jinjarecurse-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: jinjarecurse-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94a942a145b96fdcf259ec878873de97a532605dba5aca021aac230f75a6f695 |
|
MD5 | 77590e9c401d65fc1fda2826b6800ab5 |
|
BLAKE2b-256 | 8c88c938246d62be026078cfcb99da500962acb86660c8056a9bc919a52338c8 |