-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (47 loc) · 969 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bufio"
"fmt"
"log"
"os"
)
const helpMsg = `yaml2jinja converts YAML specs to Jinja templates
Usage:
yaml2jinja < /path/to/yamlspec.yaml
Examples:
yaml2jinja < test/example1.yaml
yaml2jinja < test/example1.yaml > example1.go
`
func printHelp(f string) {
helpArgs := []string{"-h", "--help", "help"}
for _, m := range helpArgs {
if f == m {
fmt.Println(helpMsg)
os.Exit(0)
}
}
}
func main() {
// Read args
if len(os.Args) > 1 {
printHelp(os.Args[1])
}
// Read input from the console
var data string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
data += scanner.Text() + "\n"
}
//fmt.Printf(data)
if err := scanner.Err(); err != nil {
log.Fatal("Error while reading input:", err)
}
// Create yaml2jinja object and invoke Convert()
var y2j = new(Yaml2Jinja)
result, err := y2j.Convert([]byte(data))
if err != nil {
log.Fatal("Invalid YAML")
}
fmt.Println(result)
return
}