https://github.com/mashiike/yaml2text
YAML converter using golang template
https://github.com/mashiike/yaml2text
Last synced: 3 months ago
JSON representation
YAML converter using golang template
- Host: GitHub
- URL: https://github.com/mashiike/yaml2text
- Owner: mashiike
- License: mit
- Created: 2020-06-10T07:37:16.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T20:35:03.000Z (about 2 years ago)
- Last Synced: 2024-06-19T15:06:40.689Z (11 months ago)
- Language: Go
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yaml2text
This is YAML converter using golang template.

I was tired of copying and pasting many similar files.
Do not use it to generate text files (or any code) that requires more advanced parsing.## Simple usecase.
yaml file convert to any text file.for example. following yaml file convert to sql file with go template file.
(testdata/basic.yaml)
```yaml
fields:
- name: hoge
sql: COALESCE(SUM(hoge), 0)
- name: fuga
sql: ARRAY_AGG(fuga)
- name: piyo
sql: AVG(piyo)table: yamlyaml
```go template file is this.
(testdata/basic.tpl)
```
SELECT{{ $length := len .fields}}{{range $i, $v := .fields }}
{{$v.sql}} AS {{$v.name}}{{if lt $i (sub $length 1)}},{{end}}{{end}}
FROM {{ .table }}
```and, execute following comand.
```shell
$ yaml2text -template testdata/basic.tpl testdata/basic.yaml
SELECT
COALESCE(SUM(hoge), 0) AS hoge,
ARRAY_AGG(fuga) AS fuga,
AVG(piyo) AS piyo
FROM yamlyaml
```It is convenient to use Makefile and shell redirection together.
## Install
### Homebrew (macOS only)
```
$ brew install mashiike/tap/yaml2text
```### Binary packages
[Releases](https://github.com/mashiike/mysqlbatch/releases)