sigil

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2015 License: BSD-3-Clause Imports: 7 Imported by: 0

README

Sigil

CircleCI IRC Channel

Standalone string interpolator and template processor

$ echo '${name} is{{ range seq ${count:-3} }} cool{{ end }}!' | sigil name=Sigil
Sigil is cool cool cool!

Sigil is a command line tool for template processing and POSIX-compliant variable expansion. It was created for configuration templating, but can be used for any text processing.

Getting Sigil

$ curl https://dl.gliderlabs.com/sigil/latest/$(uname -sm|tr \  _).tgz \
    | tar -zxC /usr/local/bin

Other releases can be downloaded from Github Releases.

Using Sigil

Template text can be provided via STDIN or from a file if provided with the -f flag. Any other arguments are key-values in the form <key>=<value>. They are used as variables.

  • echo 'Hello, $name' | sigil name=Jeff
  • sigil -f config.tmpl var1=foo "var2=Hello world"
Variables
POSIX style

There are two forms of variable syntax in Sigil. The first is POSIX style, which among other features allows default values or enforces required values:

  • $variable - normal POSIX style
  • ${variable:-"default"} - expansion with default value
  • ${variable:?} - fails when not set

Environment variables are also available as POSIX style variables. This makes Sigil great for quick and simple string interpolation.

Template style

The other syntax to use variables is consistent with the rest of the templating syntax. It uses {{ and }} to define template expressions. Variable expansion in this form is simply used as:

  • {{ $variable }}

You can do much more with this syntax, such as modifier pipelines. All of which is explained below.

Functions

There are a number of builtin functions that can be used as modifiers, conditional tests, expansion data sources, and more. There are two references for functions available:

Here are a few examples:

  • {{ $variable | capitalize }}
  • {{ include "file.tmpl" "var1=foo" "var2=bar" }}
  • {{ file "example.txt" | replace "old" "new" }}
  • {{ json "file.json" | pointer "/Widgets/0/Name" }}
Conditionals
  • {{ if expr }} true {{ end }}
  • {{ if expr }} true {{ else }} false {{ end }}
  • {{ if expr }} true {{ else if expr }} also true {{ end }}
Loops / Iteration
  • {{ range expr }} element: {{.}} {{ end }}
  • {{ range expr }} elements {{ else }} no elements {{ end }}
Full Syntax

Lots more is possible with this template syntax. Sigil is based on Go's text/template package. You can read full documentation there.

License

BSD

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TemplatePath    []string
	PosixPreprocess bool
)

Functions

func Execute

func Execute(input []byte, vars map[string]string, name string) (bytes.Buffer, error)

func LookPath added in v0.3.0

func LookPath(file string) (string, error)

func PopPath added in v0.3.0

func PopPath()

func PushPath added in v0.3.0

func PushPath(path string)

func Register

func Register(fm template.FuncMap)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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