{"id":15593767,"url":"https://github.com/kasvith/teks","last_synced_at":"2025-08-12T00:36:54.347Z","repository":{"id":57535566,"uuid":"189854398","full_name":"kasvith/teks","owner":"kasvith","description":"Easily get custom go template based outputs to your command-line tool. Like in docker/kubernetes","archived":false,"fork":false,"pushed_at":"2019-07-08T09:25:01.000Z","size":22,"stargazers_count":40,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T15:16:27.838Z","etag":null,"topics":["cli","cli-app","cli-formatter","clitools","command","docker-like-output","easy-to-use","format","formatter","formatting","go","go-template","golang","helper","librar","output","table","tabular","text-template","text-templating"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kasvith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-02T14:10:04.000Z","updated_at":"2024-09-27T11:35:37.000Z","dependencies_parsed_at":"2022-08-29T00:40:57.893Z","dependency_job_id":null,"html_url":"https://github.com/kasvith/teks","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasvith%2Fteks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasvith%2Fteks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasvith%2Fteks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasvith%2Fteks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kasvith","download_url":"https://codeload.github.com/kasvith/teks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251297104,"owners_count":21566751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","cli-app","cli-formatter","clitools","command","docker-like-output","easy-to-use","format","formatter","formatting","go","go-template","golang","helper","librar","output","table","tabular","text-template","text-templating"],"created_at":"2024-10-03T00:21:24.465Z","updated_at":"2025-04-28T10:41:22.344Z","avatar_url":"https://github.com/kasvith.png","language":"Go","readme":"# teks : awesome outputs for your commands\n\n[![Build Status](https://travis-ci.com/kasvith/teks.svg?branch=master)](https://travis-ci.com/kasvith/teks) [![Go Report Card](https://goreportcard.com/badge/github.com/kasvith/teks)](https://goreportcard.com/report/github.com/kasvith/teks) [![GoDoc](https://godoc.org/github.com/kasvith/teks?status.svg)](https://godoc.org/github.com/kasvith/teks)\n\n**teks** brings painless output formating for your commands. Docker/Kubernetes provides custom formatting via `go-templates`.\n**teks** brings the power into any application providing a smooth intergration as a library. \n\n\u003e **teks** is hevily inspired by [Docker CLI](https://github.com/docker/cli)\n\n# Install\n\n`teks` is a go package. To use it execute\n```\ngo get github.com/kasvith/teks\n```\n\n# Available formatting options\n\n| Name | Usage |\n| --- | --- |\n| `json` | Output is formatted as JSON |\n| `jsonPretty` | Outputs a human-readable JSON with indented by 2 spaces |\n| `upper` | Convert string to uppercase |\n| `lower` | Convert string to lowercase |\n| `split` | Splits strings given by `string` and `sep` |\n| `join` | Joins strings by given separator |\n| `title` | Convert the first letter to uppercase of a string |\n\n# Example\n\nIn this example we are going to printout details of few persons using teks.\n\n```go\npackage main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"text/template\"\n\n\t\"github.com/kasvith/teks\"\n)\n\n// Person represents a human being or whatever\ntype Person struct {\n\tName    string\n\tAge     int\n\tAddress string\n}\n\nfunc main() {\n\tvar format string\n\t// default one will printout Name and Age in tabular format\n\tflag.StringVar(\u0026format, \"format\", \"table {{.Name}}\\t{{.Age}}\", \"format of output\")\n\tflag.Parse()\n\n\t// whatever data you have\n\tpersons := []Person{\n\t\t{\"Kasun\", 24, \"Earth\"},\n\t\t{\"John Doe\", 34, \"Somewhere on earth\"},\n\t\t{\"Spongebob\", 30, \"Under Sea\"},\n\t\t{\"Harry Potter\", 30, \"4 Privet Drive, Little Whinging, Surrey\"},\n\t}\n\n\t// create new context\n\tctx := teks.NewContext(os.Stdout, format)\n\n\t// create a renderer function to match signature defined in teks.Renderer\n\trenderer := func(w io.Writer, t *template.Template) error {\n\t\tfor _, p := range persons {\n\t\t\tif err := t.Execute(w, p); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\t_, _ = w.Write([]byte{'\\n'})\n\t\t}\n\t\treturn nil\n\t}\n\n\t// headers for table\n\ttableHeaders := map[string]string{\n\t\t\"Age\":     \"Age\",\n\t\t\"Name\":    \"Name\",\n\t\t\"Address\": \"Address\",\n\t}\n\n\t//override header functions if you want\n\t//teks.HeaderFuncs = template.FuncMap{\n\t//\t\"split\": strings.Split,\n\t//}\n\n\t// execute context and write to our output\n\tif err := ctx.Write(renderer, tableHeaders); err != nil {\n\t\tfmt.Println(\"Error executing template:\", err.Error())\n\t}\n}\n\n```\n\nNow run program as follows\n\n```\n➜ go run simple.go \nName                Age\nKasun               24\nJohn Doe            34\nSpongebob           30\nHarry Potter        30\n```\n\nLet's pretty print Name and Address in tabular format\n```\n➜ go run simple.go --format \"table {{.Name}}\\t{{.Address}}\"\nName                Address\nKasun               Earth\nJohn Doe            Somewhere on earth\nSpongebob           Under Sea\nHarry Potter        4 Privet Drive, Little Whinging, Surrey\n```\n\nLet's make Name UPPERCASE\n```\n➜ go run simple.go --format \"table {{upper .Name}}\\t{{.Address}}\"\nNAME                Address\nKASUN               Earth\nJOHN DOE            Somewhere on earth\nSPONGEBOB           Under Sea\nHARRY POTTER        4 Privet Drive, Little Whinging, Surrey\n```\n\nYou can change behavior of these headers by providing custom HeaderFuncs.\n\n[![asciicast](https://asciinema.org/a/249879.svg)](https://asciinema.org/a/249879)\n\n# Contribution\n\nAll contributions are welcome. Raise an Issue or a Pull Request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasvith%2Fteks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkasvith%2Fteks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasvith%2Fteks/lists"}