tmplgen
A tiny Go CLI that generates lines of strings from a template file. Each line
in the input may contain one or more regex patterns wrapped in {{ … }};
tmplgen expands each pattern into a randomly generated string that matches
it, cycling round-robin through the input until the requested number of
lines has been produced.
Install
go install github.com/JordanSinko/tmplgen@latest
Usage
tmplgen [flags] <input-file>
Flags
| Flag |
Default |
Description |
-n, --count |
required |
total number of lines to generate (must be > 0) |
-o, --out |
stdout |
output file path |
--delim-open |
{{ |
opening delimiter |
--delim-close |
}} |
closing delimiter |
--seed |
time-based |
RNG seed for reproducible output |
--max-repeat |
10 |
maximum expansion length for unbounded quantifiers (+, *) |
Example
Given templates.txt:
user_{{[a-z]{6}}}@example.com
order-{{[0-9]{8}}}
{{[A-Z]{3}}}-{{[0-9]{4}}}
Run:
tmplgen -n 6 --seed 42 templates.txt
Produces 6 lines, round-robining through the three templates:
user_abcdef@example.com
order-12345678
XYZ-1234
user_ghijkl@example.com
order-87654321
ABC-5678
Pattern syntax
Patterns use Go's regexp/syntax (Perl
mode), resolved by
lucasjones/reggen. Common patterns:
{{[a-z]{10}}} 10 lowercase letters
{{[A-Z0-9]{5}}} 5 uppercase letters or digits
{{\d{3}-\d{4}}} phone-number-ish
{{(cat|dog|fish)}} alternation
{{[a-z]+}} one or more lowercase (bounded by --max-repeat)
- Blank / whitespace-only lines are ignored and don't participate in the
round-robin rotation.
- Leading and trailing whitespace on each line is trimmed.
# has no special meaning; commented-looking lines are treated as data.
- CRLF line endings are accepted.
Determinism
Same --seed, same input, same --count produces identical output.
Decreasing --count yields a strict prefix of the larger-count output. No
guarantees are made across versions of tmplgen or its dependencies.
License
MIT — see LICENSE.