Templating

Templates allow interpolation of values from Flags, Arguments, and Configuration into certain aspects of commands.

For example, the exec command type supports templates for placing arguments into the command being run.

The Go template language is used for all template processing.

Only some fields are parsed through templates, the documentation for each command type will call out what is supported.

Reference

An example template use was shown in the exec documentation:

command: |
      {{ default .Config.Cowsay "cowsay" }} "{{ .Arguments.message | escape }}"

This example demonstrates accessing the .Config and .Arguments structures and using some functions.

Available Data

KeyDescription
.ConfigData stored in the configuration file for this application
.ArgumentsData supplied by users using command arguments
.FlagsData supplied by users using command flags
.InputParsed JSON input from a previous step, available in transform contexts only

Available Functions

FunctionDescriptionExample
requireAsserts that some data is available, errors with the given message on failure or a default message when empty{{ require .Config.Password "Password not set in the configuration" }}
escapeEscapes a string for use in shell arguments{{ escape .Arguments.message }}
read_fileReads a file{{ read_file .Arguments.file }}
defaultChecks a value, if its not supplied uses a default{{ default .Config.Cowsay "cowsay" }}
envReads an environment variable{{ env "HOME" }}
UserWorkingDirReturns the directory the user is in when running the command{{ UserWorkingDir }}
AppDirReturns the directory the application definition is in{{ AppDir }}
TaskDirAlias for AppDir{{ TaskDir }}

In addition to the above, the Sprig functions library is available in most template contexts including commands, scaffolds and transforms.