No description, website, or topics provided.
Switch branches/tags
Clone or download
Latest commit 8414bee Apr 7, 2017
Permalink
Failed to load latest commit information.
test Initial commit Jan 29, 2017
.gitignore Initial commit Jan 29, 2017
LICENSE Initial commit Jan 29, 2017
README.md Initial commit Jan 29, 2017
runstache-0.0.3-0.rockspec Bump version to 0.0.3-0 Apr 7, 2017
runstache.lua Drop support for --env commandline flags Apr 7, 2017

README.md

runstache.lua

A standalone template instantiation script for mustache templates in Lua.

Usage

./runstache.lua [<config filename>] [<template filename>] [<output filename>]

All arguments are optional, providing sensible defaults.

Values set in <config> can be overridden on the command line by specifying -e positional_value or -e key=value.

Config filename

The file config filename is executed as a Lua script and is expected to return a table that is used as the context of the template.

It may return a second value, which shall be a preprocessing function. This function is called with config as its argument and is expected to return a (modified) config. See below for examples.

Defaults to: Name of the script (arg[0]) with .lua replaced with .cfg.

Template filename

The template file to instantiate.

Defaults to: stdin

Output filename

Defaults to: stdout

Example

Config file (example.cfg)

return {
  example = {
    value = 1,
  },
},
function(config)
  config.additional = assert(config[1])
  return config
end

Template (example.yaml)

example:
  value: {{example.value}}
  additional: {{additional}}
  template: |
    {{>example.template}}

Nested template (example.template)

Template
With
{{additional}}
Value

Command line and output

The first line is the command that was run and not part of the output.

# ./runstache.lua example.cfg example.yaml -e "much more"
example:
  value: 1
  additional: much more
  template: |
    Template
    With
    much more
    Value

Advanced example

Config

local merge = require "std.table".merge

return {
  hosts = {
    orange = {
      ip = "10.0.0.1",
    },
    blue = {  
      ip = "10.0.0.2",
    },
  },
},
function(config)
  for hostname, host in pairs(config.hosts) do
    host.hostname = hostname
  end
  return merge(config, config.hosts[config.hostname])
end

Template

some-service:
  hostfile: {{hostname}}.cfg
  ip: {{ip}}

Command line and output

The first line is the command that was run and not part of the output.

# ./runstache.lua example.cfg example.yaml -e hostname=orange
some-service:
  hostfile: orange.cfg
  ip: 10.0.0.1