This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (75 loc) · 2.05 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
package main
import (
"flag"
"fmt"
"os"
"sort"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform/terraform"
"github.com/olekukonko/tablewriter"
"github.com/viostream/terraform-provider-snowflake/pkg/provider"
)
func main() {
b := flag.Bool("doc", false, "spit out docs for resources here")
flag.Parse()
if *b {
doc()
} else {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: func() terraform.ResourceProvider {
return provider.Provider()
},
})
}
}
func doc() {
// schema := provider.Provider().Schema
resources := provider.Provider().ResourcesMap
names := make([]string, 0)
for k := range resources {
names = append(names, k)
}
sort.Strings(names)
for _, name := range names {
resource := resources[name]
fmt.Printf("\n### %s\n\n", name)
fmt.Printf("#### properties\n\n")
table := tablewriter.NewWriter(os.Stdout)
table.SetAutoWrapText(false)
table.SetHeader([]string{"name", "type", "description", "optional", " required", "computed", "default"})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
properties := make([]string, 0)
for k := range resource.Schema {
properties = append(properties, k)
}
sort.Strings(properties)
for _, property := range properties {
s := resource.Schema[property]
table.Append([]string{property, typeString(s.Type), s.Description, boolString(s.Optional), boolString(s.Required), boolString(s.Computed), interfaceString(s.Default)})
}
table.Render()
}
}
func typeString(t schema.ValueType) string {
switch t {
case schema.TypeBool:
return "bool"
case schema.TypeInt:
return "int"
case schema.TypeFloat:
return "float"
case schema.TypeString:
return "string"
case schema.TypeList:
return "list"
case schema.TypeMap:
return "map"
case schema.TypeSet:
return "set"
}
return "?"
}
func boolString(t bool) string { return fmt.Sprintf("%t", t) }
func interfaceString(t interface{}) string { return fmt.Sprintf("%#v", t) }