codegen
A small tool to automatically generate code starting from one or more template fil(s), and a csv file.
Contents
Installation
go install github.com/Abathargh/codegen/cmd/codegen@latest
Binaries are available from the release section.
Get it as a library
# either clone everything and build it
go get github.com/Abathargh/codegen@latest
How To
This tool is able to substitute data from csv files into template files containing
tokens in the #n# format, where n is a number greater or equal to 1. You could also use different
separators, '#' is the default one.
If you have a template file called templ.c, and a csv called data.csv like these:
#define test_#1# #2#
test,123
test2,456
test3,testing
You may call codegen like this:
codegen -t templ.c -d data.csv
This is what will be generated:
#define test_test 123
#define test_test2 456
#define test_test3 testing
Usage
usage: codegen [-h|--help] -t|--template "<value>" [-t|--template "<value>"
...] -d|--data "<value>" [-s|--separator "<value>"] [-l|--limit
<integer>]
Generates files based on templates and csv tables. Template
files contain tokens in the #n# format, where n is a number and
# is the default separator. If the passed csv has n columns, the
application will be able to substitute tokens with the
corresponding column values, up to a total of n,for each row of
the csv file.
Arguments:
-h --help Print help information
-t --template a template to process in order to generate code, it should
contain tokens in the #n# format, where n is a number and #
is the default separator: e.g. #1# #2#
-d --data a csv file that contains the data to substitute the tokens
with
-s --separator the separator to use to identify tokens, defaults to #.
Default: #
-l --limit limits the csv substitution up to the first n rows, defaults
to 0, meaning no limit is applied. Default: 0