mitsuhiko / minijinja

MiniJinja is a powerful but minimal dependency template engine for Rust compatible with Jinja/Jinja2
https://docs.rs/minijinja/
Apache License 2.0
1.67k stars 101 forks source link

feat(cli): ability to pass data on stdin while using template source passed by parameter #623

Closed cablehead closed 2 weeks ago

cablehead commented 2 weeks ago

2.4's new --template flag is great, particularly for Nushellers for whom process substitution isn't available 😅

When the --template <TEMPLATE_STRING> is used, potentially the next file parameter could be assumed to be the DATA_FILE?

$ minijinja-cli -t 'Hi {{ name }}' -D name=@mitsuhiko
Hi @mitsuhiko

# unable to pass the data as stdin (or other file)?
$ jo name='\@mitsuhiko' | minijinja-cli -f json -t 'Hi {{ name }}' -
error: the argument '--template <TEMPLATE_STRING>' cannot be used with '[TEMPLATE_FILE]'

Usage: minijinja-cli --format <FORMAT> --template <TEMPLATE_STRING> [TEMPLATE_FILE] [DATA_FILE]

For more information, try '--help'.

Thank you for everything 🙏

mitsuhiko commented 2 weeks ago

I think a cleaner way is to allow an empty argument to be set:

$ echo '{"name":"x"}' | minijinja-cli -f json -t 'Hi {{ name }}!' '' -
Hi x!
cablehead commented 2 weeks ago

Look great 🙏