Crates.io | scaf |
lib.rs | scaf |
version | 1.0.0 |
source | src |
created_at | 2023-09-18 23:14:57.689417 |
updated_at | 2023-09-18 23:14:57.689417 |
description | Create text from templates. |
homepage | https://github.com/trip-flip/scaf |
repository | https://github.com/trip-flip/scaf |
max_upload_size | |
id | 976360 |
size | 5,853 |
Generate text from templates.
scaf
so far has only been tested on UTF-8 files. The template file syntax will also conflict with sh
variables if there are conflicting names.
Here's an example template file, let's call it foo.txt
:
The quick ${color} ${animal0} jumps over the lazy ${animal1}.
color
, animal0
, and animal1
are variables that will be replaced if scaf
is passed an argument that assigns one of those names, like below:
scaf --var color=green
--var animal0=frog
--var animal1=turtle
foo.txt
This will print to stdout:
The quick green frog jumps over the lazy turtle.
Variables can omitted safely, so the template variable will not be replaced. However you must provide at least one file or scaf
fails early.
With that said, multiple files can be used, with their contents first concatenated then replaced as necessary:
foo.txt
${msg1}
and
bar.txt
${msg2}
with this invocation:
scaf --var "msg1=Hello world!"
--var "msg2=Goodbye friends!"
foo.txt bar.txt
results in:
foo.txt
Hello world!
bar.txt
Goodbye friends!