From 92ced56127df90dce193e050926c265b12874d75 Mon Sep 17 00:00:00 2001 From: artaasadi Date: Thu, 7 Nov 2024 16:00:58 +0100 Subject: [PATCH] fix: update resource_type script --- .../resource_type/resource_types_generator.go | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pkg/sdk/runable/resource_type/resource_types_generator.go b/pkg/sdk/runable/resource_type/resource_types_generator.go index 4d163332..4e2c26ab 100644 --- a/pkg/sdk/runable/resource_type/resource_types_generator.go +++ b/pkg/sdk/runable/resource_type/resource_types_generator.go @@ -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() { @@ -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 @@ -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