minijinja-cli

Build Status License Crates.io rustc 1.61.0

minijinja-cli is a command line executable that uses MiniJinja to render Jinja2 templates directly from the command line to stdout.

cargo install minijinja-cli

minijinja-cli my-template.j2 data.json

Arguments

minijinja-cli has two positional arguments to refer to files. Either one of them can be set to - to read from stdin. This is the default for the template, but only one can be set to stdin at once.

Options

Formats

The following formats are supported:

Examples

Render a template with a string and integer variable:

minijinja-cli template.j2 -D name=World -D count:=3

Render a template with variables from stdin:

echo '{"name": "World"}' | minijinja-cli -f json template.j2 -

Evaluate an expression and print the result:

minijinja-cli --env -E "ENV.HOME or ENV.USERPROFILE"

REPL:

``` minijinja-cli --repl -D name=World MiniJinja Expression REPL Type .help for help. Use .quit or ^D to exit.

name|upper "WORLD" range(3) [0, 1, 2] ```

Behavior

Templates can extend other templates or include them. Paths are relative to the parent template. So when you are in foo/bar.j2 and you include utils.j2 it will load foo/utils.j2. Including of templates can be disabled for security reasons with --no-include.

All filters and functions from MiniJinja and minijinja-contrib are available.

Upon failure a stack trace is rendered to stderr.

The repl mode lets you execute MiniJinja expressions.

Compile-Time Features

By default all features are enabled. The following features can be explicitly selected when the defaults are turned off:

Sponsor

If you like the project and find it useful you can become a sponsor.

License and Links