1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
netencode-mustache(1) "netencode manual"

# NAME

netencode-mustache - Render Mustache templates with netencode data

# SYNOPSIS

*netencode-mustache*

# DESCRIPTION

*netencode-mustache* renders Mustache templates using netencode data as the 
template context. The tool reads a Mustache template from standard input and 
uses netencode data from an environment variable to populate the template.

This enables generating configuration files, documentation, or any text output 
from structured netencode data using the Mustache templating language.

# OPTIONS

*netencode-mustache* takes no command-line arguments.

# INPUT

*Template*
	Mustache template read from standard input

*Data*
	Netencode data read from the *TEMPLATE_DATA* environment variable

# OUTPUT

The rendered template is written to standard output.

# ENVIRONMENT

*TEMPLATE_DATA*
	Environment variable containing netencode data to use as template context. 
	This variable must be set and contain valid netencode.

# DATA MAPPING

Netencode values are converted to Mustache data types:

*Text values*
	Become Mustache strings

*Numbers*
	Become Mustache strings (decimal representation)

*Booleans*
	Become Mustache booleans (true/false)

*Unit values*
	Become Mustache null

*Records*
	Become Mustache objects (hash maps)

*Lists*
	Become Mustache arrays

*Tagged values*
	Booleans are supported: *<4:true|u,* and *<5:false|u,* become Mustache booleans. Other tagged values are not supported and will cause the program to panic.

*Binary data*
	Not supported (will cause the program to panic)

# EXIT STATUS

*0*
	Success

*1*
	Error: invalid template, missing environment variable, or invalid netencode data

# EXAMPLES

Render a simple template:

```
export TEMPLATE_DATA='{25:<4:name|t5:Alice,<3:age|n:30,}'
echo "Hello {{name}}, you are {{age}} years old!" | netencode-mustache
# Output: Hello Alice, you are 30 years old!
```

Generate configuration files:

```
export TEMPLATE_DATA='{30:<6:server|t7:example,<4:port|n:8080,}'
cat config.template | netencode-mustache > config.conf
```

Use with record data:

```
env-to-netencode | netencode-record-get DATABASE_CONFIG | \
  env TEMPLATE_DATA="$(cat)" netencode-mustache < db.conf.template
```

Process lists:

```
export TEMPLATE_DATA='[21:t5:Alice,t3:Bob,t7:Charlie,]'
echo "Users: {{#.}}{{.}} {{/.}}" | netencode-mustache
# Output: Users: Alice Bob Charlie
```

Chain with other tools:

```
json-to-netencode < data.json | \
  env TEMPLATE_DATA="$(cat)" netencode-mustache < report.template
```

# TEMPLATE SYNTAX

*netencode-mustache* supports standard Mustache template syntax:

- *{{variable}}* - Variable substitution
- *{{#section}}...{{/section}}* - Sections (conditionals/loops)  
- *{{^section}}...{{/section}}* - Inverted sections
- *{{!comment}}* - Comments
- *{{>partial}}* - Partials (not recommended for simple use cases)

# NOTES

- The *TEMPLATE_DATA* environment variable must contain valid netencode
- Boolean tagged values (*<4:true|u,* and *<5:false|u,*) are supported and recommended
- Other tagged values and binary data are not supported and will cause panic
- Template syntax errors will cause the program to exit with error
- Use *env* command to set *TEMPLATE_DATA* in pipelines

# SEE ALSO

*netencode*(5), *env-to-netencode*(1), *netencode-record-get*(1), *json-to-netencode*(1), *netencode-filter*(1), *netencode-plain*(1), *netencode-pretty*(1)

Mustache specification: https://mustache.github.io/