-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (53 loc) · 1.57 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
60
61
62
63
64
65
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
log "github.com/Sirupsen/logrus"
"github.com/vharitonsky/iniflags"
)
var (
rootDir = flag.String("dir", ".", "start dir")
descriptionPath = flag.String("desc", "", "terraform markdown description")
outPath = flag.String("out", "", "output result filepath")
)
type Line struct {
Name string `form:"Name" json:"Name" xml:"Name"`
Optional bool `form:"Optional" json:"Optional" xml:"Optional"`
Description string `form:"Description" json:"Description" xml:"Description"`
}
type ResourceArgument Line
type ResourceAttribute Line
type Resource struct {
Name string `form:"Name" json:"Name" xml:"Name"`
Arguments []ResourceArgument `form:"Arguments" json:"Arguments" xml:"Arguments"`
Attributes []ResourceAttribute `form:"Attributes" json:"Attributes" xml:"Attributes"`
}
func main() {
iniflags.Parse()
log.SetLevel(log.InfoLevel)
log.Debug("reading directory: ", *rootDir)
awsResources, err := loadResources(*descriptionPath)
if err != nil {
log.Error("error loading aws resources: ", err)
return
}
state := NewHierarchyState()
err = loadModule(*rootDir, ".", awsResources, state)
if err != nil {
log.Errorf("error reading root module '%s' (SKIPPED): %v", *rootDir, err)
}
jsonState, err := json.Marshal(*state)
if nil != err {
log.Error(err)
}
if "" != *outPath {
err = ioutil.WriteFile(*outPath, jsonState, 0755)
if nil != err {
log.Errorf("writing to file (%s) error: %v", *outPath, err)
}
} else {
fmt.Print(string(jsonState))
}
}