v0.0.185 add Meta() to enums

This commit is contained in:
Mike Schwörer 2023-07-19 19:34:39 +02:00
parent d8270e53ed
commit 0971f60c30
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 13 additions and 16 deletions

View File

@ -293,15 +293,7 @@ func fmtOutput(cs string, enums []EnumDef, pkgname string) string {
str += "" + "\n" str += "" + "\n"
str += "func (e " + enumdef.EnumTypeName + ") ValuesMeta() []EnumMetaValue {" + "\n" str += "func (e " + enumdef.EnumTypeName + ") ValuesMeta() []EnumMetaValue {" + "\n"
str += " return []EnumMetaValue{" + "\n" str += " return " + enumdef.EnumTypeName + "ValuesMeta()"
for _, v := range enumdef.Values {
if hasDescr {
str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: langext.Ptr(\"%s\")},", v.VarName, v.VarName, strings.TrimSpace(*v.Description)) + "\n"
} else {
str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: nil},", v.VarName, v.VarName) + "\n"
}
}
str += " }" + "\n"
str += "}" + "\n" str += "}" + "\n"
str += "" + "\n" str += "" + "\n"
@ -330,6 +322,15 @@ func fmtOutput(cs string, enums []EnumDef, pkgname string) string {
str += "}" + "\n" str += "}" + "\n"
str += "" + "\n" str += "" + "\n"
str += "func (e " + enumdef.EnumTypeName + ") Meta() EnumMetaValue {" + "\n"
if hasDescr {
str += " return EnumMetaValue{VarName: e.VarName(), Value: e, Description: langext.Ptr(e.Description())}"
} else {
str += " return EnumMetaValue{VarName: e.VarName(), Value: e, Description: nil}"
}
str += "}" + "\n"
str += "" + "\n"
str += "func Parse" + enumdef.EnumTypeName + "(vv string) (" + enumdef.EnumTypeName + ", bool) {" + "\n" str += "func Parse" + enumdef.EnumTypeName + "(vv string) (" + enumdef.EnumTypeName + ", bool) {" + "\n"
str += " for _, ev := range __" + enumdef.EnumTypeName + "Values {" + "\n" str += " for _, ev := range __" + enumdef.EnumTypeName + "Values {" + "\n"
str += " if string(ev) == vv {" + "\n" str += " if string(ev) == vv {" + "\n"
@ -348,11 +349,7 @@ func fmtOutput(cs string, enums []EnumDef, pkgname string) string {
str += "func " + enumdef.EnumTypeName + "ValuesMeta() []EnumMetaValue {" + "\n" str += "func " + enumdef.EnumTypeName + "ValuesMeta() []EnumMetaValue {" + "\n"
str += " return []EnumMetaValue{" + "\n" str += " return []EnumMetaValue{" + "\n"
for _, v := range enumdef.Values { for _, v := range enumdef.Values {
if hasDescr { str += " " + v.VarName + ".Meta(),\n"
str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: langext.Ptr(\"%s\")},", v.VarName, v.VarName, strings.TrimSpace(*v.Description)) + "\n"
} else {
str += " " + fmt.Sprintf("EnumMetaValue{VarName: \"%s\", Value: %s, Description: nil},", v.VarName, v.VarName) + "\n"
}
} }
str += " }" + "\n" str += " }" + "\n"
str += "}" + "\n" str += "}" + "\n"

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.184" const GoextVersion = "0.0.185"
const GoextVersionTimestamp = "2023-07-19T19:29:59+0200" const GoextVersionTimestamp = "2023-07-19T19:34:39+0200"