Skip to content

Commit 22653f9

Browse files
committed
generate list/schema/string_resource.go
1 parent b30df31 commit 22653f9

File tree

5 files changed

+405
-61
lines changed

5 files changed

+405
-61
lines changed

list/schema/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
// plan, and state data. Schemas are implemented via the resource.Resource type
77
// Schema method.
88
package schema
9+
10+
//go:generate go run github.com/hashicorp/terraform-plugin-framework/list/schema/generate

list/schema/generate/main.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"text/template"
8+
)
9+
10+
func main() {
11+
path, err := os.Getwd()
12+
if err != nil {
13+
fmt.Println("Error getting current directory:", err)
14+
os.Exit(1)
15+
}
16+
fmt.Println("Current directory:", path)
17+
18+
features := struct {
19+
Optionality bool
20+
Computedness bool
21+
Sensitivity bool
22+
WriteOnly bool
23+
RequiredForImport bool
24+
Defaultiness bool
25+
Planning bool
26+
}{
27+
true, // Optionality
28+
false, // Computedness
29+
false, // Sensitivity
30+
false, // WriteOnly
31+
false, // RequiredForImport
32+
false, // Defaultiness
33+
false, // Planning
34+
}
35+
36+
t, err := template.ParseGlob("generate/*.go.tmpl")
37+
if err != nil {
38+
fmt.Println("Error parsing templates:", err)
39+
os.Exit(1)
40+
}
41+
42+
file, err := os.OpenFile(path+"/string_attribute.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
43+
if err != nil {
44+
fmt.Println("Error opening file:", err)
45+
os.Exit(1)
46+
}
47+
defer file.Close()
48+
49+
err = t.ExecuteTemplate(file, "string_attribute.go.tmpl", features)
50+
if err != nil {
51+
fmt.Println("Error executing template:", err)
52+
os.Exit(1)
53+
}
54+
55+
cmd := exec.Command("go", "fmt", path+"/string_attribute.go")
56+
err = cmd.Run()
57+
if err != nil {
58+
fmt.Println("Error formatting file:", err)
59+
os.Exit(1)
60+
}
61+
fmt.Println("File generated and formatted successfully: string_attribute.go")
62+
}

0 commit comments

Comments
 (0)