v0.0.402 add PackageName() and TypeName() to enums_codegen
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m12s

This commit is contained in:
2024-03-10 12:49:31 +01:00
parent ed53f297bd
commit 409d6e108d
10 changed files with 107 additions and 37 deletions

View File

@@ -25,6 +25,10 @@ type IDDef struct {
Name string
}
type IDGenOptions struct {
DebugOutput *bool
}
var rexIDPackage = rext.W(regexp.MustCompile(`^package\s+(?P<name>[A-Za-z0-9_]+)\s*$`))
var rexIDDef = rext.W(regexp.MustCompile(`^\s*type\s+(?P<name>[A-Za-z0-9_]+)\s+string\s*//\s*(@id:type).*$`))
@@ -34,7 +38,9 @@ var rexIDChecksumConst = rext.W(regexp.MustCompile(`const ChecksumIDGenerator =
//go:embed id-generate.template
var templateIDGenerateText string
func GenerateIDSpecs(sourceDir string, destFile string) error {
func GenerateIDSpecs(sourceDir string, destFile string, opt *IDGenOptions) error {
debugOutput := langext.Coalesce(opt.DebugOutput, false)
files, err := os.ReadDir(sourceDir)
if err != nil {
@@ -80,13 +86,18 @@ func GenerateIDSpecs(sourceDir string, destFile string) error {
pkgname := ""
for _, f := range files {
fmt.Printf("========= %s =========\n\n", f.Name())
fileIDs, pn, err := processIDFile(sourceDir, path.Join(sourceDir, f.Name()))
if debugOutput {
fmt.Printf("========= %s =========\n\n", f.Name())
}
fileIDs, pn, err := processIDFile(sourceDir, path.Join(sourceDir, f.Name()), debugOutput)
if err != nil {
return err
}
fmt.Printf("\n")
if debugOutput {
fmt.Printf("\n")
}
allIDs = append(allIDs, fileIDs...)
@@ -112,7 +123,7 @@ func GenerateIDSpecs(sourceDir string, destFile string) error {
return nil
}
func processIDFile(basedir string, fn string) ([]IDDef, string, error) {
func processIDFile(basedir string, fn string, debugOutput bool) ([]IDDef, string, error) {
file, err := os.Open(fn)
if err != nil {
return nil, "", err
@@ -153,7 +164,11 @@ func processIDFile(basedir string, fn string) ([]IDDef, string, error) {
FileRelative: rfp,
Name: match.GroupByName("name").Value(),
}
fmt.Printf("Found ID definition { '%s' }\n", def.Name)
if debugOutput {
fmt.Printf("Found ID definition { '%s' }\n", def.Name)
}
ids = append(ids, def)
}
}