Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
/ gotmpl Public archive

gotmpl is a versatile CLI tool designed for rendering templates using various data sources such as stdin, files, or web resources. With support for multiple data inputs and flexible output options, gotmpl empowers you to effortlessly generate templated content, whether for display on stdout or saving to a file.

License

Notifications You must be signed in to change notification settings

StevenCyb/gotmpl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gotmpl

gotmpl is a command-line interface (CLI) tool for template rendering. Whether you're working with templates from stdin, files, or web resources, gotmpl simplifies the process by allowing you to provide multiple data inputs through arguments, files, or URLs. The rendered output can be directed to stdout or saved into a specified file.

Example

$ echo "Hello, {{.Name}}" | go run main.go -data '{"Name": "John"}'
Hello, John%     

Usage

Currently supported arguments can be listed as follow.

$ ./gotmpl --help
Usage: gotmpl [options] -tmpl {URL,Path} -out {Path}
Options:
  -data value
        Data to use {URL,Path,JSON}. Multiple allowed.
  -help
        Show this help message.
  -out string
        Render output {Path} or stdout.
  -tmpl string
        Template to use {URL,Path} or stdin.

This cli tool uses the go text template engine. A documentation for that is available here. In general, the tool can be used as follow:

  1. provide a template
    • from a file like -tmpl /some/path/mail_template.txt
    • from a web resource like -tmpl https://some.url/mail_template (requires http or https prefix)
    • from std like echo "template" | ... (without -tmpl argument)
  2. provide data (for multiple data source see note below)
    • from a JSON formatted file like -tmpl /some/path/user_a.json
    • from a JSON formatted web resource like -tmpl https://some.url/user_a (requires http or https prefix)
    • directly as JSON formatted string -tmpl '{...}' or -tmpl '[...]'
  3. define the output
    • into a file like -out result.txt
    • stdout is used by default if -out not defined

NOTE: When using multiple data sources, they are placed in an array (keeping the order). For example the templates will look as follow multiple data sources:

echo "Name: {{(index . 0).Name}}, Age: {{(index . 1).Age}}" | ./gotmpl -data '{"Name": "Nina"}' -data '{"Age": 33}'
# OR
echo "Name: {{index . 0 \"Name\"}}, Age: {{index . 1 \"Age\"}}" | ./gotmpl -data '{"Name": "Nina"}' -data '{"Age": 33}'

With single data source:

echo "Name: {{.Name}}, Age: {{.Age}}" | ./gotmpl -data '{"Name": "Nina", "Age": 33}'

About

gotmpl is a versatile CLI tool designed for rendering templates using various data sources such as stdin, files, or web resources. With support for multiple data inputs and flexible output options, gotmpl empowers you to effortlessly generate templated content, whether for display on stdout or saving to a file.

Topics

Resources

License

Stars

Watchers

Forks

Languages