0.0.1 |
|
---|
#26 in #render-template
7KB
67 lines
CLI Utility for Rendering Templates with TOML Args
This is a CLI utility written in Rust that allows you to render templates using args specified in a TOML file. The tool uses the clap and handlebars libraries for command line argument parsing and template rendering respectively.
Installation
To use this tool, you need to have Rust installed on your system.
You can then install the tool using cargo
, Rust's package manager.
cargo install tompl
Usage
tompl render --input ./path/to/config.toml --output ./out/rendered.txt
TOML File Format
The TOML file should have the following format:
template = "./path/to/template.txt"
[params]
param1 = "value1"
nparam2 = "value2"
user = "{{env.USER}}"
template
: The path to the template file that you want to render.params
: A table containing the arguments that you want to pass to the template.
You can use the env
parameter in the params
table to access environment variables.
Example
Assuming that the config.toml
file has the following contents:
template = "./template.txt"
[params]
name = "John"
age = 30
And the template.txt
file has the following contents:
Hello, {{name}}!
You are {{age}} years old.
Environment variables:
{{#each env}}
- {{@key}}: {{this}}
{{/each}}
The above command will render the template using the arguments specified in the TOML file and write the output to the output.txt
file
Dependencies
~5MB
~100K SLoC