Skip to content

Commit

Permalink
fix: update resource_type script
Browse files Browse the repository at this point in the history
  • Loading branch information
artaasadi committed Nov 7, 2024
1 parent 98e5540 commit 92ced56
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pkg/sdk/runable/resource_type/resource_types_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ type ResourceType struct {
}

var (
output = flag.String("output", "", "Path to the output file for resource types")
indexMap = flag.String("index-map", "", "Path to the output file for index map")
output = flag.String("output", "", "Path to the output file for resource types")
indexMap = flag.String("index-map", "", "Path to the output file for index map")
resourceTypesList = flag.String("resource-types-list", "", "Path to the output file for index map")
)

func main() {
Expand Down Expand Up @@ -74,6 +75,11 @@ func main() {
indexMap = &v
}

if resourceTypesList == nil || len(*resourceTypesList) == 0 {
v := "resource_types_list.go"
resourceTypesList = &v
}

// Initialize a strings.Builder to construct the output file content
b := &strings.Builder{}
b.WriteString(fmt.Sprintf(`package provider
Expand Down Expand Up @@ -200,6 +206,23 @@ var ReverseMap = map[string]string{
if err != nil {
panic(err)
}

// Generate the index map file as before
b = &strings.Builder{}
b.WriteString(fmt.Sprintf(`package configs
var ResourceTypesList = []string{
`))
for _, resourceType := range resourceTypes {
b.WriteString(fmt.Sprintf(" \"%s\",\n", resourceType.ResourceName))
}
b.WriteString(fmt.Sprintf(`}`))

// Write the index map to the specified file
err = os.WriteFile(*resourceTypesList, []byte(b.String()), os.ModePerm)
if err != nil {
panic(err)
}
}

// escapeString ensures that any quotes in the strings are properly escaped
Expand Down

0 comments on commit 92ced56

Please sign in to comment.