• Stars
    star
    24
  • Rank 952,927 (Top 20 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 3 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

"to be defined" - a really simple way to create text templates with placeholders

tbd

Go Report Card ย ย ย  Release ย ย ย  codecov

"to be defined"

A really simple way to create text templates with placeholders.

This tool is deliberately simple and trivial, no advanced features.

If you need advanced templates rendering which supports complex syntax and a huge list of datasources (JSON, YAML, AWS EC2 metadata, BoltDB, Hashicorp > Consul and Hashicorp Vault secrets), I recommend you use one of these:

Built-in Variables

When executed inside a Git repository, tbd automatically exports some variables related to the Git repository which may be useful in the build phase.

These variables are: ARCH, OS, REPO_COMMIT, REPO_HOST, REPO_NAME, REPO_ROOT, REPO_TAG, REPO_TAG_CLEAN, REPO_URL, TIMESTAMP.

Try it! With tbd in your PATH, go in a Git folder and type:

$ tbd vars
+----------------+------------------------------------------+
| ARCH           | amd64                                    |
| OS             | linux                                    |
| REPO_COMMIT    | a3193274112d3a6f5c2a0277e2ca07ec238d622f |
| REPO_HOST      | github.com                               |
| REPO_NAME      | tbd                                      |
| REPO_ROOT      | lucasepe                                 |
| REPO_TAG       | v0.1.1                                   |
| REPO_TAG_CLEAN | 0.1.1                                    |
| REPO_URL       | https://github.com/lucasepe/tbd          |
| TIMESTAMP      | 2021-07-26T14:22:36Z                     |
+----------------+------------------------------------------+

Obviously in your case the values โ€‹โ€‹will be different.

How does a template looks like ?

A template is a text document in which you can insert placeholders for the text you want to make dynamic.

  • a placeholder is delimited by {{ and }} - (i.e. {{ FULL_NAME }})
  • all text outside placeholders is copied to the output unchanged

Example:

apiVersion: v1
kind: Pod
metadata:
  name: {{ metadata.name }}
  labels:
    app: {{ metadata.labels.app }}
 spec:
  containers:
    - name: {{ container.1.name }}
      image: {{ container.1.image }}
      ports:
        - containerPort: {{ container.1.port }}
    - name: {{ container.2.name }}
      image: {{ container.2.image }}
      ports:
        - containerPort: {{ container.2.port }}

Another example:

{{ greeting }}

I will be out of the office from {{ start.date }} until {{ return.date }}. 
If you need immediate assistance while Iโ€™m away, please email {{ contact.email }}.

Best,
{{ name }}

How can I define placeholders values?

Create a text file in which you enter the values for the placeholders.

  • define a placeholder value using KEY = value (or KEY: value)
  • empty lines are skipped
  • lines beginning with # are treated as comments

Example:

# metadata values
metadata.name = rss-site
metadata.labels.app = web

# containers values
container.1.name = front-end
container.1.image = nginx
container.1.port = 80

container.2.name = rss-reader
container.2.image: nickchase/rss-php-nginx:v1
container.2.port: 88

Another example...

greeting: Greetings
start.date: August, 9 
return.date: August 23
contact.email: [email protected]
name: Pinco Pallo 

How fill in the template?

Use the merge command

$ tbd merge /path/to/your/template /path/to/your/envfile

Example:

$ tbd merge testdata/sample.tbd testdata/sample.vars

๐Ÿ‘‰ you can also specify an HTTP url to fetch your template and/or placeholders values.

Example:

$ tbd merge https://raw.githubusercontent.com/lucasepe/tbd/main/testdata/sample.tbd \
    https://raw.githubusercontent.com/lucasepe/tbd/main/testdata/sample.vars

and the output is...

Greetings

I will be out of the office from August, 9 until August 23. 
If you need immediate assistance while Iโ€™m away, please email [email protected].

Best,
Pinco Pallo

How to list all template placeholders?

Use the marks command.

$ tbd marks /path/to/your/template

Example:

$ tbd marks testdata/sample.tbd
greeting
start.date
return.date
contact.email
name

How to list all variables?

Use the vars command.

$ tbd vars /path/to/your/envfile

Example:

$ tbd vars testdata/sample.vars
+----------------+------------------------------------------+
| Label          | Value                                    |
+----------------+------------------------------------------+
| ARCH           | amd64                                    |
| OS             | linux                                    |
| REPO_COMMIT    | a3193274112d3a6f5c2a0277e2ca07ec238d622f |
| REPO_HOST      | github.com                               |
| REPO_NAME      | tbd                                      |
| REPO_ROOT      | lucasepe                                 |
| REPO_TAG       | v0.1.1                                   |
| REPO_TAG_CLEAN | 0.1.1                                    |
| REPO_URL       | https://github.com/lucasepe/tbd          |
| TIMESTAMP      | 2021-07-26T14:17:49Z                     |
| contact.email  | [email protected]                    |
| greeting       | Greetings                                |
| name           | Pinco Pallo                              |
| return.date    | August 23                                |
| start.date     | August, 9                                |
+----------------+------------------------------------------+

As you can see, since I ran the command in a Git repository, there are also relative variables.

How to install?

If you have golang installed:

$ go install github.com/lucasepe/tbd@latest

This will create the executable under your $GOPATH/bin directory.

Ready-To-Use Releases

If you don't want to compile the sourcecode yourself, here you can find the tool already compiled for:

  • MacOS
  • Linux
  • Windows

Credits

Thanks to @valyala for the fasttemplate library - which I have modified by adding and removing some functions for the tbd purpose.

More Repositories

1

draft

Generate High Level Cloud Architecture diagrams using YAML syntax.
Go
572
star
2

modgv

Converts 'go mod graph' output into Graphviz's DOT language
Go
474
star
3

yml2dot

Turn YAML into beautiful Graph
Go
132
star
4

jumble

Create (not just) diagrams stitching, connecting and labelling images on a grid using HCL syntax (like terraform!).
Go
105
star
5

crumbs

Turn asterisk-indented text lines into mind maps
Go
101
star
6

codename

Generate random, pronounceable, sometimes even memorable, "superhero like" codenames - just like Docker does with container names.
Go
100
star
7

tiles

Commandline tool that makes building tilesets and rendering static tilemaps super easy!
Go
51
star
8

lib_mysqludf_haversine

MySQL UDF to compute the Haversine formula
C
46
star
9

go-ps4

Search your favorite PS4 games from Playstation Store using the Command Line
Go
44
star
10

g2d

Craft beautiful geometric art using code.
Go
43
star
11

using-client-go

Source code related to my Golang Notebook "Using client-go"
Go
30
star
12

grasp

Create strong passwords using words that are easy for you to remember. A password manager that does not require any type of storage
Go
22
star
13

uri

A commandline tool to resolve URI Templates expressions as specified in RFC 6570.
Go
17
star
14

pwsafe

Cross Platform simple and secure password management from commandline.
Go
16
star
15

yo

An alternative syntax to generate YAML (or JSON) from commandline. => https://youtu.be/QL6DsCLFQ30
Go
10
star
16

clon

A convenient syntax to generate JSON (or YAML) for commandline "mumbo-jumbo".
Go
9
star
17

gptcli

An interactive ChatGPT client featuring shortcuts and auto-complete.
Go
7
star
18

kvs

KVS is a commandline tool to store and organize key-value data on your local file system.
Go
6
star
19

slackify

Upload files to your preferred Slack channels using CLI or pipe in stdin
Go
3
star
20

memo

Store and organize notes on your local file system.
Go
3
star
21

locker

Store secrets on your local file system.
Go
3
star
22

lib_mysqludf_qrencode

MySQL UDF for QRCode generation
C
2
star
23

yamldo

Create YAML documents from a directory tree or a ZIP archive.
Go
2
star
24

local-container-registry

Create a local development environment to pull/push your images without relying on external services.
Makefile
1
star
25

expose

Markdown Driven Slides Viewer
Go
1
star
26

terraform-provider-codename

The Terraform Codename provider is used to generate random _"superhero like"_ codenames.
Go
1
star
27

xdg

Go
1
star
28

giso

isometric graphics library
Go
1
star
29

mini

Parse (sort of) INI files like "flag" package in Go.
Go
1
star
30

nginx_apikey_access_filter_module

Nginx filter to restrict the access at your backend APIs
1
star
31

image-cloner

kubernetes controller that watches the Deployments and โ€œcachesโ€ the images by re-uploading to your own registry repository and reconfiguring the applications to use these copies
Go
1
star
32

markdown

A CommonMark-compliant markdown parser and renderer in Go.
Go
1
star
33

gg

Go Graphics - 2D rendering in Go with a simple API.
Go
1
star
34

todoist

A Go library for Todoist's REST API
Go
1
star
35

totp

Simple library to generate TOTP codes and parse TOTP URIs
Go
1
star
36

boilr

Projects and text templates using ${var} expansion syntax.
Go
1
star
37

strcase

Utilities for converting strings between different cases
Go
1
star
38

spinner

Simple activity indicator for your command line tools.
Go
1
star
39

envsubst

Go package emulates bash environment variable substitution
Go
1
star