Simple CLI templates generator written in Go without any external dependencies.
Press Ctrl+D to stop writing to STDIN interactively
See also GOLANG (template engine docs)[https://golang.org/pkg/html/template/]
- Install GO
- Run
go install github.com/bravepickle/templar@latest
- Go to https://github.com/bravepickle/templar/releases
- Download binary file according to your OS and architecture
- Create your own Docker container (for example, using image https://hub.docker.com/_/golang)
- Clone repository
- Run
make releaseormake buildto build binary file
- for now uses https://masterminds.github.io/sprig/ for additional functions supported
- regular templating functions for Golang packages also supported. See official docs for
text/template,html/templatepackages.
See also (default functions and usages)[https://golang.org/pkg/text/template/#hdr-Functions]
OS ENV -> item variables from batch file -> defaults in batch file
- Add binary executables for some of the architectures
- Read docs with installation and usage instructions
- Provide examples
- Support types: text, html
- Optionally use facter or similar to pass extra params from environment and similar sources
- As input use ENV values, JSON, key-values from file or directly set as params
- Read data for template by piping
- Support all formats specified
- Specify in docs all available template functions
- Support configs that contain multiple templates to generate - some kind of templates aggregator to easily template files in batches
- Support both html and text formatters, e.g. by adding flag
templar build --html ...to a command. By default, use text - Add raw|unescape function to FuncMap for html text formatting. Should skip HTML escapes for
html/templatepackage. E.g.return template.HTML(text). - On general help list commands with basic description. See
docker compose helpas an example for formatting and texts - On command help view full description. Make new functions for detailed and short description
- Add debug command to see all resulting variables available for the template
- If debug is disabled then do not show error messages. Instead, show help blocks with non-zero exit code
- Add SchemaJSON file for
batch.jsonfiles. - Add support of JSONL format. For STDIN and other to stream data. Instead of ReadAll, we should process each template per line on-fly and skip blank lines.
- Batch support input formats - env, json
-
--verbose,--debugflags reconsider their application - Read from stdin only if some flag passed. E.g.
--input -
$ templar
Usage: templar [OPTIONS] COMMAND [COMMAND_ARGS]
templar generate template contents with provided variables
Commands:
init init default files structure for building templates
build render template contents with provided variables
help show help information on command or subcommand usage. Type "templar help help" to see help command usage information
version show application information on its build version and directories
Options:
-debug
debug mode
-no-color
disable color and styles output
-verbose
verbose output
-workdir string
working directory path (default "/home/user/templar")
$ templar --no-color help build
Usage: templar [OPTIONS] build [COMMAND_OPTIONS]
build render template contents with provided variables
Options:
-clear
clear ENV variables before building variables to avoid collisions
-dump string
show all available variables for the template to use and stop processing. Pass optionally --verbose or --debug flags for more information. Allowed dump formats: env, json, json_compact
-format string
input file format for variables' file. Allowed: env, json, batch (default "env")
-input string
file path which contains variables for template to use or batch file. Format should match "-format" value
-output string
output file path, If empty, outputs to stdout. If "-batch" option is used, specifies output directory
-skip
skip generation if target files already exist
-template string
template file path, If empty and "-batch" not defined, reads from stdin
Examples:
$ templar build --input .env --format env --template template.tpl --output output.txt
# generates output.txt file from the provided template.tpl and .env variables in env format (is the default one, can be ommitted)
$ NAME=John templar build --template template.tpl --output output.txt
# generates output.txt file from the provided template.tpl and provided env variable
$ echo "My name is {{ .NAME }}" | NAME=John templar build
# generates output.txt file from the provided template.tpl and provided env variable
$ templar build --format json --input vars.json --dump env
# dumps to stdout combined OS ENV and JSON variables. Used to check what variables are available
$ templar --debug build --input vars.env --dump json --clear
# dump variables in JSON format and display their values (--debug flag was added). OS ENV variables will be omitted