It's as good a name as any i guess. /jʌːtsi/
yutc
is a templating command line interface written in (surprise, surprise) Go.
It is designed to parse and merge data files, and apply them to templates.
The application supports reading data from both local files and URLs,
and can output the results to a file or stdout.
Download the latest build or any other version from the releases page. Put it somewhere on your computer. Add it to your path. If you are using this you probably already know how to do that.
You can use yutc
by passing it a list of templates along with various options:
yutc [OPTIONS]... [ <templates> ... ]
Usage of yutc:
-c, --common-templates string Templates to be shared across all arguments in template list. Can be a file or a URL. Can be specified multiple times.
-d, --data string Data file to parse and merge. Can be a file or a URL. Can be specified multiple times and the inputs will be merged.
-o, --output string Output file/directory, defaults to stdout (default "-")
-w, --overwrite Overwrite existing files
--version Print the version and exit
toYaml
is a custom template function that converts the input to a yaml representation.
similar to the toYaml
in helm
.
mustToYaml
is also available, which will panic if the input cannot be converted to yaml.
{{ . | toYaml }}
fromYaml
is a custom template function that converts the input to a go object.
similar to the fromYaml
in helm
.
mustFromYaml
is also available, which will panic if the input cannot be converted to a go object.
{{ fromYaml . | .SomeField | toString }}
wrapText
uses textwrap to wrap text to a specified width.
wrapComment
is a wrapper around wrapText
that adds a comment character to the beginning of each line.
{{ wrapText 80 .SomeText }}
{{ wrapComment "#" 80 .SomeText }}
toToml
is a custom template function that converts the input to a TOML representation.
Similar to toYaml
but for TOML format.
mustToToml
is also available, which will panic if the input cannot be converted to TOML.
{{ . | toToml }}
fromToml
is a custom template function that converts TOML input to a go object.
Similar to fromYaml
but for TOML format.
mustFromToml
is also available, which will panic if the input cannot be converted to a go object.
{{ fromToml . | .SomeField | toString }}
fileGlob
- Returns a list of files matching a glob pattern.
fileStat
- Returns file statistics as a map with keys like Mode, Size, ModTime, etc.
fileRead
- Reads the entire contents of a file as a string.
fileReadN
- Reads the first N bytes of a file as a string.
{{- range fileGlob "*.txt" }}
File: {{ . }}
{{- end }}
{{- $stat := fileStat "myfile.txt" }}
Size: {{ $stat.Size }} bytes
{{ fileRead "config.txt" }}
{{ fileReadN 100 "largefile.txt" }}
pathAbsolute
- Returns the absolute path of the given path.
pathIsDir
- Returns true if the path is a directory.
pathIsFile
- Returns true if the path is a file.
pathExists
- Returns true if the path exists.
{{ pathAbsolute "./relative/path" }}
{{- if pathExists "myfile.txt" }}
{{- if pathIsFile "myfile.txt" }}
File exists: {{ pathAbsolute "myfile.txt" }}
{{- end }}
{{- end }}
{{- if pathIsDir "mydirectory" }}
Directory found!
{{- end }}
type
returns the Go type of the given value as a string.
{{ type . }}
{{ type "hello" }}
{{ type 42 }}
include
allows you to include and render other templates as text within the current template.
This is the exact same as the include
function in Helm.
{{ include "shared-template" . }}
yutc -o ~/.ssh/config \
-d sshConfig/data.yaml \
./sshConfig/config.tmpl
a file
yutc -o patch.yaml \
-d ./talosPatches/controlplane-workloads.yaml \
-d talosPatches/disable-cni.yaml \
-d talosPatches/disable-discovery.yaml \
-d talosPatches/install-disk.yaml \
-d talosPatches/kubelet.yaml \
-d talosPatches/local-storage.yaml \\
-d talosPatches/names.yaml \
<(echo "{{ . | toYaml }}")
alternate form using matching
yutc -o patch.yaml \
--data ./talosPatches \
--data-match './talosPatches/.*\.yaml' \
<(echo "{{ . | toYaml }}")
For some reason you want to list the files in a directory and embed them in a file in a custom format:
{{- $files := fileGlob "./*/*" -}}
{{- range $path := $files }}
{{- $stat := fileStat $path }}
{{- $username := (env "USERNAME" | default (env "USER") )}}
{{- $usernameFString := printf "%s%d%s " "%-" (len $username) "s"}}
{{ printf "%-12s" $stat.Mode }}{{ printf $usernameFString $username }}{{ pathAbsolute $path}}
{{- end }}
-rw-rw-rw- adam C:\Users\adam\code\yet-unnamed-template-cli\.git\COMMIT_EDITMSG
-rw-rw-rw- adam C:\Users\adam\code\yet-unnamed-template-cli\.git\FETCH_HEAD
-rw-rw-rw- adam C:\Users\adam\code\yet-unnamed-template-cli\.git\HEAD
-rw-rw-rw- adam C:\Users\adam\code\yet-unnamed-template-cli\.git\ORIG_HEAD
-rw-rw-rw- adam C:\Users\adam\code\yet-unnamed-template-cli\.git\config
-rw-rw-rw- adam C:\Users\adam\code\yet-unnamed-template-cli\.git\description
drwxrwxrwx adam C:\Users\adam\code\yet-unnamed-template-cli\.git\hooks
........
yutc --data .\testFiles\data\data1.yaml --data .\testFiles\data\data2.yaml .\testFiles\templates\simpleTemplate.tmpl
JSON representation of the merged input:
---
{
"ditto": [
"woohooo",
"yipeee"
],
"dogs": [],
"thisIsNew": 1000,
"thisWillMerge": {
"value23": 23,
"value24": 24
}
}
---
Yaml representation:
---
ditto:
- woohooo
- yipeee
dogs: []
thisIsNew: 1000
thisWillMerge:
value23: 23
value24: 24
---
See README.data.yaml and README.md.tmpl for the source data and template
I had very specific requirements that gomplate, gucci, and others weren't quite able to meet. Both of those a great apps, and if you So really i just made this for myself at my day-job, but if anyone else finds it useful, here it is. Enjoy the weird niche features!
Others will likely be more actively maintained, and are rad so check them out!