templcat

command
v0.0.0-...-3738d89 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 8 Imported by: 0

README

templcat

Used to build text output from field input using a given template.

Templating engine is Go's template engine.

Usage

$  templcat --help
Usage of templcat:
  -template string
    	raw template to build with
  -templateFile string
    	file containing template to use

Simple Example

$ cat names
bob top
mary top
ray middle
$ cat names|templcat --template '{"employee":{"name":{{index . 0}}, "level":{{index . 1}}}}'
{"employee":{"name":bob, "level":top}}
{"employee":{"name":mary, "level":top}}
{"employee":{"name":ray, "level":middle}}

File Based Example

$ cat fruits
apple banana cherry date eggplant
fig
grape honeydew
jack@jack-mobile:~/working/golang/src/github.com/JackKnifed/cliTricks/templcat|master⚡
$ cat fruit_template
{
  "fruits":[{{range $index, $element := .}}
	{{if $index}},{{end}}"{{.}}"{{end}}
  ]
}
$ cat fruits|templcat --templateFile fruit_template
{
  "fruits":[
	"apple"
	,"banana"
	,"cherry"
	,"date"
	,"eggplant"
  ]
}

{
  "fruits":[
	"fig"
  ]
}

{
  "fruits":[
	"grape"
	,"honeydew"
  ]
}

This of course leaves you free to pretty it yourself.

⇒  cat fruits|templcat --templateFile fruit_template|prettycat
{
  "fruits": [
    "apple",
    "banana",
    "cherry",
    "date",
    "eggplant"
  ]
}
{
  "fruits": [
    "fig"
  ]
}
{
  "fruits": [
    "grape",
    "honeydew"
  ]
}

Bugs

  • There must be a newline at the end of output - the last line is ignored.
  • Blank lines are not ignored.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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