/
main.go
59 lines (45 loc) · 1.17 KB
/
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
58
59
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
//############################################################################
func pushError(f string, args ...interface{}) {
fmt.Printf(fmt.Sprintf("yamllinter: %s", f), args...)
os.Exit(1)
}
//############################################################################
func pushInfo(f string, args ...interface{}) {
fmt.Printf(fmt.Sprintf("yamllinter: %s", f), args...)
}
//############################################################################
func main() {
if len(os.Args) < 2 {
pushError("unrecognized input arguments: [usage: yamllinter <*.yaml>]")
}
var filePath string
verbose := false
if os.Args[1] == "-v" {
verbose = true
filePath = os.Args[2]
} else {
filePath = os.Args[1]
}
if verbose {
pushInfo("input file is %q", filePath)
}
if _, err := os.Stat(filePath); err != nil {
pushError("input file not found")
}
buf, err := ioutil.ReadFile(filePath)
if err != nil {
pushError("could not read input file")
}
t := make(map[string]interface{})
if err := yaml.Unmarshal(buf, &t); err != nil {
pushError("syntax error in %q: %s", filePath, err)
}
os.Exit(0)
}