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 }}
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!