Git Product home page Git Product logo

yutc's Introduction

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!

yutc's People

Contributors

adam-huganir avatar

Stargazers

 avatar

Watchers

 avatar

yutc's Issues

feat: add --copy-ignored for files that are ignored

for we we add ignore back as an option, we want the ability to copy over the ignored files.

use case:
a template folder that has a helm deployment in it, and we do not want to template the helm templates as well as our own, so we do

yutc ... --template-ignore '^chart/templates/.*' --copy-ignored ./some-template-directory```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.