-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
130 lines (103 loc) · 2.62 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"flag"
"fmt"
"os"
"text/template"
"github.com/hashicorp/terraform/builtin/providers/aws"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/helper/schema"
)
type terms struct {
Keywords map[string]bool
KeywordColor string
Resources map[string]bool
ResourceColor string
DataSources map[string]bool
DataSourceColor string
Providers map[string]bool
ProviderColor string
Functions map[string]bool
FunctionColor string
VarColor string
}
var t = &terms{
Keywords: make(map[string]bool),
Resources: make(map[string]bool),
DataSources: make(map[string]bool),
Providers: make(map[string]bool),
Functions: make(map[string]bool),
}
func scan(r *schema.Resource, out map[string]bool) {
for k, v := range r.Schema {
if v.Elem != nil {
c, ok := v.Elem.(*schema.Resource)
if ok {
scan(c, out)
}
}
out[k] = true
}
}
func main() {
var (
flags *flag.FlagSet
uc string
provider *schema.Provider
tpl *template.Template
err error
)
flags = flag.NewFlagSet("colors", flag.ExitOnError)
flags.StringVar(&t.KeywordColor, "keyword", colorWhite, "color of keywords")
flags.StringVar(&t.ResourceColor, "resource", colorBrightCyan, "color of resources")
flags.StringVar(&t.DataSourceColor, "data-source", colorBrightCyan, "color of data sources")
flags.StringVar(&t.ProviderColor, "provider", colorRed, "color of providers")
flags.StringVar(&t.FunctionColor, "func", colorYellow, "color of functions")
flags.StringVar(&t.VarColor, "var", colorYellow, "color of variables")
flags.Parse(os.Args[1:])
if uc = colors.exists(t.KeywordColor, t.ResourceColor, t.DataSourceColor, t.ProviderColor, t.FunctionColor, t.VarColor); uc != "" {
fmt.Printf("unknown color %s\n", uc)
flags.PrintDefaults()
os.Exit(2)
}
provider = aws.Provider().(*schema.Provider)
for k, v := range provider.ResourcesMap {
scan(v, t.Keywords)
t.Resources[k] = true
}
for k, v := range provider.DataSourcesMap {
scan(v, t.Keywords)
t.DataSources[k] = true
}
for k := range provider.Schema {
t.Keywords[k] = true
}
for k := range config.Funcs() {
t.Functions[k] = true
}
t.Providers["aws"] = true
var addKeywords = []string{
"private_key",
"script_path",
"bastion_user",
"bastion_password",
"bastion_private_key",
"bastion_host",
"bastion_port",
"connection",
"provisioner",
"inline",
}
for _, k := range addKeywords {
t.Keywords[k] = true
}
tpl = template.New("template")
tpl, err = tpl.ParseFiles("template")
if err != nil {
panic(err)
}
err = tpl.Execute(os.Stdout, t)
if err != nil {
panic(err)
}
}