autogen pb gui table fixes

This commit is contained in:
Jeff Carr 2025-02-20 09:38:47 -06:00
parent 261d54485c
commit 68eea60f16
5 changed files with 41 additions and 5 deletions

View File

@ -65,6 +65,7 @@ message Fruit {
Pears notpears = 6; Pears notpears = 6;
Pears fakepears = 7; Pears fakepears = 7;
repeated Basket gifts = 8; repeated Basket gifts = 8;
int64 price = 9; // `autogenpb:sort`
} }
// "Fruits" MUST EXIST and start exactly this way // "Fruits" MUST EXIST and start exactly this way

View File

@ -80,6 +80,7 @@ message File {
map<string, string> iterMap = 11; map<string, string> iterMap = 11;
repeated Sort toSort = 12; // variables that are repeated can have the standard functions generated (Sort(), etc) repeated Sort toSort = 12; // variables that are repeated can have the standard functions generated (Sort(), etc)
string goPath = 13; // the version to use in a func NewMsgName() string goPath = 13; // the version to use in a func NewMsgName()
bool doGui = 14; // if a gui.pb.go file should be created
} }
// I know, I know, the whole point of using protobuf // I know, I know, the whole point of using protobuf

View File

@ -32,8 +32,13 @@ func (pb *Files) makeGuiFile(pf *File) error {
} }
if v.VarType == "string" { if v.VarType == "string" {
log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName) log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
guiAddFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName) guiAddStringFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
// log.Printf("make Add function here %s %s\n", v.VarType, v.VarName) continue
}
if v.VarType == "int64" {
log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
guiAddIntFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
continue
} }
/* /*
continue continue
@ -221,7 +226,7 @@ func guiStringFuncs(w io.Writer, ZOOPB string, FRUITS string, FRUIT string) {
fmt.Fprintln(w, "}") fmt.Fprintln(w, "}")
} }
func guiAddFunc(w io.Writer, FRUITS string, FRUIT string, BRAND string) { func guiAddStringFunc(w io.Writer, FRUITS string, FRUIT string, BRAND string) {
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (t *"+FRUITS+"Table) Add"+BRAND+"() {") fmt.Fprintln(w, "func (t *"+FRUITS+"Table) Add"+BRAND+"() {")
fmt.Fprintln(w, " // t.pb.Order = append(t.pb.Order, "+BRAND+")") fmt.Fprintln(w, " // t.pb.Order = append(t.pb.Order, "+BRAND+")")
@ -241,3 +246,24 @@ func guiAddFunc(w io.Writer, FRUITS string, FRUIT string, BRAND string) {
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
*/ */
} }
func guiAddIntFunc(w io.Writer, FRUITS string, FRUIT string, BRAND string) {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (t *"+FRUITS+"Table) Add"+BRAND+"() {")
fmt.Fprintln(w, " // t.pb.Order = append(t.pb.Order, "+BRAND+")")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " t.AddIntFunc(\""+BRAND+"\", func(m *"+FRUIT+") int {")
fmt.Fprintln(w, " return int(m."+BRAND+")")
fmt.Fprintln(w, " })")
fmt.Fprintln(w, "}")
/*
fmt.Fprintln(w, "func (t *"+FRUITS+"Table) AddMemory() {")
fmt.Fprintln(w, " t.pb.Order = append(t.pb.Order, \"Memory\")")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "func (t *"+FRUITS+"Table) AddCpus() {")
fmt.Fprintln(w, " t.pb.Order = append(t.pb.Order, \"Cpus\")")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
*/
}

View File

@ -188,8 +188,10 @@ func main() {
badExit(err) badExit(err)
} }
if err := pb.makeGuiFile(pf); err != nil { if pf.DoGui {
badExit(err) if err := pb.makeGuiFile(pf); err != nil {
badExit(err)
}
} }
} }

View File

@ -10,6 +10,7 @@ import (
"strings" "strings"
"go.wit.com/lib/fhelp" "go.wit.com/lib/fhelp"
"go.wit.com/log"
"golang.org/x/text/cases" "golang.org/x/text/cases"
"golang.org/x/text/language" "golang.org/x/text/language"
) )
@ -188,5 +189,10 @@ func (pf *File) parseForMessage(line string) *MsgName {
msg.DoMarshal = true msg.DoMarshal = true
// log.Info("Added Marshal=true:", msg.Name) // log.Info("Added Marshal=true:", msg.Name)
} }
if strings.Contains(line, "autogenpb:gui") {
log.Info("got autogenpb:gui")
pf.DoGui = true
// os.Exit(-1)
}
return msg return msg
} }