tmpl

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 14 Imported by: 0

README

tmpl

tmpl allows to apply variables from JSON/TOML/YAML files, environment variables or CLI arguments to template files using Golang text/template and functions from the Sprig project.

Project status

This project is in a very early stage. Things might break !

Usage

For simplicity, everything is output on stdout. To write the result in a file, use shell redirection.

If a variable is not found and the strict mode is disabled (default disabled), each missing value will be replaced with an empty string.

  • Print help/usage message.
# $ tmpl
# $ tmpl -h
$ tmpl --help
USAGE: tmpl [OPTIONS] INPUT

INPUT is a template file or '-' for stdin

OPTIONS:
  -f value
        load variables from JSON/TOML/YAML files (format: file path)
  -s    exit on any error during template processing (default false)
  -v value
        use one or more variables from the command line (format: name=value)
  • stdin and environment variables.
$ echo 'Editor = {{ env "EDITOR" }}, Shell = {{ env "SHELL" }}' | tmpl -
Editor = nvim, Shell = /bin/bash
  • stdin and CLI variables.
$ tmpl -v foo=bar - <<< 'Hello, {{ .foo }} !'
Hello, bar !
  • Sample from this repository

Output is not pasted here because of its length.

$ tmpl -f ./stores/data.yaml ./inputs/sample.txt.tmpl

Configuration

No configuration needed. Everything is done on the command line.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL