Skip to content

Commit

Permalink
update README for new usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tnyeanderson committed Mar 27, 2023
1 parent cc1cc19 commit 7d4de99
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@

This is as easy as it gets! A minimal CLI for go templates.

Read JSON data from stdin and apply it to the template file. Alternatively,
read the template from stdin and the JSON data from a file!
Read JSON/YAML data from stdin and apply it to the template file.
Alternatively, read the template from stdin and the JSON/YAML data from a file.

Functions from [sprig](https://github.com/Masterminds/sprig) are included in
`timplit`.
Functions from [sprig](https://github.com/Masterminds/sprig) are included and
available in timplit.

## Examples
## Installation

Read JSON from stdin and apply it to a template file:
```bash
cat data.json | timplit template.tmpl

# Same as
timplit template.tmpl <data.json
go install github.com/tnyeanderson/timplit@latest
```

Read JSON from a file and apply it to the template from stdin:
## Usage

See usage with `timplit -h`.

## Examples

```bash
# Invert the logic with the -j flag
cat template.tmpl | timplit -j data.json
# Read JSON from stdin and apply it to a template file
cat data.json | timplit template.tmpl

# Same as above
timplit -t template.tmpl <data.json

# Same as
# Read JSON from a file and apply it to the template from stdin
timplit -j data.json <template.tmpl
```

## Top-level JSON array
# Read YAML from a file and apply it to the template from stdin
timplit -y data.yaml <template.tmpl

If the top level of the incoming JSON is an array, it will get wrapped in an
object (under the `items` property) to ensure that it can be unmarshaled.
# Read YAML from stdin and apply it to a template file
timplit -Y template.tmpl <data.yaml
```

For instance, `[1, 2, 3]` will become `{"items": [1, 2, 3]}`. See
`example/array.tmpl` and `example/array.json` for a practical demonstration.
Example JSON/YAML/template files are available in `cmd/testdata`.

0 comments on commit 7d4de99

Please sign in to comment.