yutc

module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2024 License: Apache-2.0

README

yutc yet-unnamed-template-cli

GitHub version

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.

Installation

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.

Usage

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

Custom Template Functions

toYaml and mustToYaml

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 and mustFromYaml

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 and wrapComment

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

Examples

Generate an SSH config file
yutc -o ~/.ssh/config \
     -d sshConfig/data.yaml \
     ./sshConfig/config.tmpl
Merging many yaml/json files together and outputting them to

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 }}")
Merging 2 data files and applying them to a template
 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
---
Rendering this documentation

See README.data.yaml and README.md.tmpl for the source data and template

Why?

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!

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL