Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions list/schema/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
// plan, and state data. Schemas are implemented via the resource.Resource type
// Schema method.
package schema

//go:generate go run github.com/hashicorp/terraform-plugin-framework/list/schema/generate
62 changes: 62 additions & 0 deletions list/schema/generate/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"fmt"
"os"
"os/exec"
"text/template"
)

func main() {
path, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current directory:", err)
os.Exit(1)
}
fmt.Println("Current directory:", path)

features := struct {
Optionality bool
Computedness bool
Sensitivity bool
WriteOnly bool
RequiredForImport bool
Defaultiness bool
Planning bool
}{
true, // Optionality
false, // Computedness
false, // Sensitivity
false, // WriteOnly
false, // RequiredForImport
false, // Defaultiness
false, // Planning
}

t, err := template.ParseGlob("generate/*.go.tmpl")
if err != nil {
fmt.Println("Error parsing templates:", err)
os.Exit(1)
}

file, err := os.OpenFile(path+"/string_attribute.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
fmt.Println("Error opening file:", err)
os.Exit(1)
}
defer file.Close()

err = t.ExecuteTemplate(file, "string_attribute.go.tmpl", features)
if err != nil {
fmt.Println("Error executing template:", err)
os.Exit(1)
}

cmd := exec.Command("go", "fmt", path+"/string_attribute.go")
err = cmd.Run()
if err != nil {
fmt.Println("Error formatting file:", err)
os.Exit(1)
}
fmt.Println("File generated and formatted successfully: string_attribute.go")
}
Loading
Loading