All Projects → kasvith → teks

kasvith / teks

Licence: MIT License
Easily get custom go template based outputs to your command-line tool. Like in docker/kubernetes

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to teks

table
Produces a string that represents slice data in a text table, inspired by gajus/table.
Stars: ✭ 130 (+217.07%)
Mutual labels:  format, table, output
AutoFormatInputWatcher
This repository contains input watcher for auto formatting digits in edit text
Stars: ✭ 15 (-63.41%)
Mutual labels:  formatter, formatting, format
unicode-formatter
Convert portions of text to fancy text using unicode fonts for use on Twitter and other sites that don't support rich text
Stars: ✭ 31 (-24.39%)
Mutual labels:  formatter, formatting, format
laravel-formatters
«‎Formatter» pattern for Laravel
Stars: ✭ 86 (+109.76%)
Mutual labels:  formatter, formatting
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (-19.51%)
Mutual labels:  formatter, format
awesome-python-code-formatters
A curated list of awesome Python code formatters
Stars: ✭ 168 (+309.76%)
Mutual labels:  formatter, formatting
Golite
Add essential language support for the Go language to Sublime Text 3.
Stars: ✭ 14 (-65.85%)
Mutual labels:  formatter, formatting
googlejavaformat-action
GitHub Action that formats Java files following Google Style guidelines
Stars: ✭ 66 (+60.98%)
Mutual labels:  formatter, format
li18nt
🌎 Lint your i18n translation files. Detect conflicting properties, duplicates and make it more readable and easier to maintain by formatting it!
Stars: ✭ 29 (-29.27%)
Mutual labels:  formatter, cli-app
Textrude
Code generation from YAML/JSON/CSV models via SCRIBAN templates
Stars: ✭ 79 (+92.68%)
Mutual labels:  text-templating, text-template
vue-translated
Internationalization (i18n) and localization (l10n) library for Vue.js v2.
Stars: ✭ 19 (-53.66%)
Mutual labels:  formatter, format
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-58.54%)
Mutual labels:  formatter, formatting
idea-uroborosql-formatter
Beautiful SQL Formatter for IntelliJ Platform
Stars: ✭ 18 (-56.1%)
Mutual labels:  formatter, formatting
Sublime-uroboroSQL-formatter
Beautiful SQL Formatter for Sublime Text 3
Stars: ✭ 25 (-39.02%)
Mutual labels:  formatter, formatting
winston-dev-console
Winston@3 console format aimed to improve development UX
Stars: ✭ 88 (+114.63%)
Mutual labels:  formatter, format
Nginx Config Formatter
nginx config file formatter/beautifier written in Python.
Stars: ✭ 222 (+441.46%)
Mutual labels:  formatter, formatting
Juliaformatter.jl
An opinionated code formatter for Julia. Plot twist - the opinion is your own.
Stars: ✭ 217 (+429.27%)
Mutual labels:  formatter, formatting
Editorconfig Netbeans
A NetBeans IDE plugin supporting the EditorConfig standard. ⛺
Stars: ✭ 123 (+200%)
Mutual labels:  formatter, formatting
Uncrustify
Code beautifier
Stars: ✭ 2,442 (+5856.1%)
Mutual labels:  formatter, format
format-date
📆 A small library (around 400 B when gziped & minified) to format JavaScript `Date` object using same tokens as moment.
Stars: ✭ 25 (-39.02%)
Mutual labels:  formatter, format

teks : awesome outputs for your commands

Build Status Go Report Card GoDoc

teks brings painless output formating for your commands. Docker/Kubernetes provides custom formatting via go-templates. teks brings the power into any application providing a smooth intergration as a library.

teks is hevily inspired by Docker CLI

Install

teks is a go package. To use it execute

go get github.com/kasvith/teks

Available formatting options

Name Usage
json Output is formatted as JSON
jsonPretty Outputs a human-readable JSON with indented by 2 spaces
upper Convert string to uppercase
lower Convert string to lowercase
split Splits strings given by string and sep
join Joins strings by given separator
title Convert the first letter to uppercase of a string

Example

In this example we are going to printout details of few persons using teks.

package main

import (
	"flag"
	"fmt"
	"io"
	"os"
	"text/template"

	"github.com/kasvith/teks"
)

// Person represents a human being or whatever
type Person struct {
	Name    string
	Age     int
	Address string
}

func main() {
	var format string
	// default one will printout Name and Age in tabular format
	flag.StringVar(&format, "format", "table {{.Name}}\t{{.Age}}", "format of output")
	flag.Parse()

	// whatever data you have
	persons := []Person{
		{"Kasun", 24, "Earth"},
		{"John Doe", 34, "Somewhere on earth"},
		{"Spongebob", 30, "Under Sea"},
		{"Harry Potter", 30, "4 Privet Drive, Little Whinging, Surrey"},
	}

	// create new context
	ctx := teks.NewContext(os.Stdout, format)

	// create a renderer function to match signature defined in teks.Renderer
	renderer := func(w io.Writer, t *template.Template) error {
		for _, p := range persons {
			if err := t.Execute(w, p); err != nil {
				return err
			}
			_, _ = w.Write([]byte{'\n'})
		}
		return nil
	}

	// headers for table
	tableHeaders := map[string]string{
		"Age":     "Age",
		"Name":    "Name",
		"Address": "Address",
	}

	//override header functions if you want
	//teks.HeaderFuncs = template.FuncMap{
	//	"split": strings.Split,
	//}

	// execute context and write to our output
	if err := ctx.Write(renderer, tableHeaders); err != nil {
		fmt.Println("Error executing template:", err.Error())
	}
}

Now run program as follows

➜ go run simple.go 
Name                Age
Kasun               24
John Doe            34
Spongebob           30
Harry Potter        30

Let's pretty print Name and Address in tabular format

➜ go run simple.go --format "table {{.Name}}\t{{.Address}}"
Name                Address
Kasun               Earth
John Doe            Somewhere on earth
Spongebob           Under Sea
Harry Potter        4 Privet Drive, Little Whinging, Surrey

Let's make Name UPPERCASE

➜ go run simple.go --format "table {{upper .Name}}\t{{.Address}}"
NAME                Address
KASUN               Earth
JOHN DOE            Somewhere on earth
SPONGEBOB           Under Sea
HARRY POTTER        4 Privet Drive, Little Whinging, Surrey

You can change behavior of these headers by providing custom HeaderFuncs.

asciicast

Contribution

All contributions are welcome. Raise an Issue or a Pull Request

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].