more cleanups
This commit is contained in:
parent
4e0b3b8f38
commit
b5002b158b
63
generate.go
63
generate.go
|
@ -25,7 +25,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
// add iterators for all the structs to be used
|
||||
for _, msg := range pf.allMsg() {
|
||||
funcdef := newIter(wSort, msg)
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
|
||||
// log.Printf("START COMPARE\n")
|
||||
|
@ -41,7 +41,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
}
|
||||
VARNAME := v.VarName
|
||||
funcdef := newSortType(wSort, PARENT, VARNAME)
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
}
|
||||
|
||||
funcdef := msg.newIterAll(wSort, FRUIT, APPLE, APPLES, LOCK)
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
|
||||
// log.Printf("START SELECT\n")
|
||||
|
@ -76,7 +76,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
}
|
||||
|
||||
funcdef := msg.addSelectAll(wSort, PARENT, CHILD, VARNAME, LOCK)
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
// log.Printf("END SELECT\n")
|
||||
|
||||
|
@ -113,7 +113,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
sortname := s.VarType + v.VarName
|
||||
selectName := "selectAll" + VARNAME
|
||||
funcdef := newSortBy(wSort, PARENT, s.VarType, sortname, sortby, selectName, v.VarName)
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
} else {
|
||||
// funcdef := "func (x *" + FUNCTYPE + ") SortBy" + v.VarName + "(" + v.VarType + ") *[]iter" + s.VarType + " # can not do this yet"
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
// special case
|
||||
funcdef := addLenFunc(wSort, PARENT, VARNAME, LOCK) // + " " + v.VarType + " name:" + v.VarName
|
||||
funcdef += " # is special struct=varname"
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
if PARENT == VARNAME {
|
||||
// FUNCNAME := "Append"
|
||||
|
@ -159,7 +159,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
|
||||
if PARENT == VARNAME {
|
||||
funcdef := addAllFunc(wSort, PARENT, CHILD, VARNAME)
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -208,7 +208,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
|
||||
funcdef := msg.generateFindBy(wSort, FUNCNAME, PARENT, VARNAME, s.VarType, v.VarName)
|
||||
// func (msg *MsgName) generateFindBy(w io.Writer, FUNCNAME, STRUCT, VARNAME, VARTYPE, COLOR string) string {
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
} else {
|
||||
if v.VarType == "string" {
|
||||
// probably dumb. move to a database if you need this
|
||||
|
@ -245,7 +245,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
} else {
|
||||
funcdef = msg.deleteBy(wSort, FRUIT, APPLES, APPLE, COLOR, FUNCNAME, v.VarName)
|
||||
}
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
|
||||
// AppendBy() functions. todo: fix these so Append() is for simple things and Insert() is for unique keys
|
||||
|
@ -265,7 +265,7 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
|||
} else {
|
||||
FUNCNAME = "Append" + VARNAME + "By" + v.VarName
|
||||
funcdef := msg.addAppendBy(wSort, PARENT, FUNCNAME, VARNAME, v.VarName, s.VarType)
|
||||
log.Printf("%20s %s\n", "", funcdef)
|
||||
log.Printf("Adding %s\n", funcdef)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,46 +320,3 @@ func (pf *File) specialBases(wFind io.Writer) {
|
|||
pf.Bases.simpleAppend(wFind, FRUIT, APPLES, APPLE)
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
func (parent *MsgName) addInsertByMsg(w io.Writer, FRUIT, APPLES, APPLE string) {
|
||||
// log.Printf("\tINSERT: %s %s for %s\n", APPLES, APPLE, FRUIT)
|
||||
for _, v := range parent.Vars {
|
||||
if v.HasUnique {
|
||||
var COLOR string = cases.Title(language.English, cases.NoLower).String(v.VarName)
|
||||
log.Printf("\tINSERT: (x %s) InsertBy%s(string) *%s\n", FRUIT, COLOR, APPLE)
|
||||
parent.insertBy(w, FRUIT, APPLES, APPLE, COLOR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (parent *MsgName) addAppendByMsg(w io.Writer, FRUIT, APPLES, APPLE string) {
|
||||
// log.Printf("\tAPPEND!: %s %s for %s\n", APPLES, APPLE, FRUIT)
|
||||
var COLORS []string
|
||||
|
||||
for _, v := range parent.Vars {
|
||||
if v.HasUnique {
|
||||
var COLOR string = cases.Title(language.English, cases.NoLower).String(v.VarName)
|
||||
COLORS = append(COLORS, COLOR)
|
||||
|
||||
log.Printf("\tAPPEND: (x %s) AppendUniqueBy%s(%s)\n", FRUIT, COLOR, APPLE)
|
||||
parent.appendUniqueCOLOR(w, FRUIT, APPLES, APPLE, COLOR)
|
||||
}
|
||||
}
|
||||
if len(COLORS) > 0 {
|
||||
parent.appendUnique(w, FRUIT, APPLES, APPLE, COLORS)
|
||||
}
|
||||
}
|
||||
|
||||
func (parent *MsgName) addSortByMsg(w io.Writer, FRUIT, APPLES, APPLE string) {
|
||||
log.Printf("\tSORT!: %s %s for %s\n", APPLES, APPLE, FRUIT)
|
||||
|
||||
for _, v := range parent.Vars {
|
||||
if v.HasSort {
|
||||
// log.Printf("\tSort!: %s %s for %s\n", APPLES, APPLE, v.VarName)
|
||||
newS := cases.Title(language.English, cases.NoLower).String(v.VarName)
|
||||
log.Printf("\t\t(x %s) SortdBy%s() *%sIter\n", FRUIT, newS, APPLE)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// makes Marshal and Unmarshal functions for protoWIRE protoTEXT and protoJSON
|
||||
|
@ -37,7 +35,7 @@ func (pb *Files) marshal(f *File) {
|
|||
if msg.DoMarshal {
|
||||
marshalThing(w, msg.Name)
|
||||
} else {
|
||||
log.Info("Skipping. DoMarshal = false for", msg.Name)
|
||||
// log.Info("Skipping. DoMarshal = false for", msg.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func (pf *File) syncLock(w io.Writer) {
|
|||
|
||||
func (pb *Files) addMutex(f *File) error {
|
||||
fullname := f.Pbfilename
|
||||
log.Info("pb filename:", fullname)
|
||||
// log.Info("pb filename:", fullname)
|
||||
data, err := os.ReadFile(fullname)
|
||||
if err != nil {
|
||||
log.Info("pb filename failed to read:", err)
|
||||
|
@ -55,7 +55,7 @@ func (pb *Files) addMutex(f *File) error {
|
|||
// check if autogenpb has already looked at this file
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if strings.Contains(line, "autogenpb DO NOT EDIT") {
|
||||
log.Info("autogenpb has already been run on", fullname)
|
||||
// log.Info("autogenpb has already been run on", fullname)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (pb *Files) addMutex(f *File) error {
|
|||
lines := strings.Split(string(data), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "package ") {
|
||||
log.Info("CHANGING package:", line, "to package:", f.Package)
|
||||
// log.Info("CHANGING package:", line, "to package:", f.Package)
|
||||
fmt.Fprintln(w, "package "+f.Package)
|
||||
// log.Info("CHANGING package:", line, "to package:main")
|
||||
// fmt.Fprintln(w, "package "+"main")
|
||||
|
@ -85,14 +85,14 @@ func (pb *Files) addMutex(f *File) error {
|
|||
|
||||
if f.structMatch(line) {
|
||||
if argv.Mutex {
|
||||
log.Info("Adding Mutex to:", line)
|
||||
// log.Info("Adding Mutex to:", line)
|
||||
fmt.Fprintln(w, line)
|
||||
fmt.Fprintln(w, "\tLock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb") // this must be 'Lock' or Marshal() panics?
|
||||
// fmt.Fprintln(w, "\t// auto-added by go.wit.com/apps/autogenpb")
|
||||
// fmt.Fprintln(w, "\tsync.RWMutex")
|
||||
fmt.Fprintln(w, "")
|
||||
} else {
|
||||
log.Info("Skipping. Mutex = false for:", line)
|
||||
// log.Info("Skipping. Mutex = false for:", line)
|
||||
fmt.Fprintln(w, line)
|
||||
fmt.Fprintln(w, "\t// Lock sync.RWMutex // autogenpb skipped this. needs --mutex command line arg")
|
||||
fmt.Fprintln(w, "")
|
||||
|
|
7
human.go
7
human.go
|
@ -129,13 +129,14 @@ func (msg *MsgName) printMsg() {
|
|||
}
|
||||
|
||||
func checkCmd(cmd string) {
|
||||
path, err := exec.LookPath(cmd)
|
||||
// path, err := exec.LookPath(cmd)
|
||||
_, err := exec.LookPath(cmd)
|
||||
if err != nil {
|
||||
fmt.Printf("\n%s is not in the PATH\n", cmd)
|
||||
// fmt.Printf("\n%s is not in the PATH\n", cmd)
|
||||
userInstructions()
|
||||
log.Sleep(2)
|
||||
} else {
|
||||
fmt.Printf("%s is available at %s\n", cmd, path)
|
||||
// fmt.Printf("%s is available at %s\n", cmd, path)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ func (pb *Files) protoParse(pf *File) error {
|
|||
if err := pb.hasPluralMessage(pf); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info(pf.Filename, "is valid so far")
|
||||
|
||||
// read in the .proto file
|
||||
data, err := os.ReadFile(pf.Filename)
|
||||
|
@ -101,13 +100,13 @@ func (pb *Files) protoParse(pf *File) error {
|
|||
continue
|
||||
}
|
||||
if msgvar.IsRepeated {
|
||||
log.Info("ADDING ITER MAP", curmsg.Name, msgvar.VarType)
|
||||
// log.Info("ADDING ITER MAP", curmsg.Name, msgvar.VarType)
|
||||
pf.IterMap[curmsg.Name] = msgvar.VarType
|
||||
}
|
||||
|
||||
if strings.Contains(line, "autogenpb:sort") {
|
||||
newS := cases.Title(language.English, cases.NoLower).String(parts[1])
|
||||
log.Info("Addded Sort:", newS, "in struct", curmsg.Name)
|
||||
// log.Info("Addded Sort:", newS, "in struct", curmsg.Name)
|
||||
curmsg.Sort = append(curmsg.Sort, newS)
|
||||
msgvar.HasSort = true
|
||||
}
|
||||
|
@ -115,7 +114,7 @@ func (pb *Files) protoParse(pf *File) error {
|
|||
if strings.Contains(line, "autogenpb:unique") {
|
||||
newU := parts[1]
|
||||
newU = cases.Title(language.English, cases.NoLower).String(newU)
|
||||
log.Info("Added Unique:", newU, "in struct", curmsg.Name)
|
||||
// log.Info("Added Unique:", newU, "in struct", curmsg.Name)
|
||||
curmsg.Unique = append(curmsg.Unique, newU)
|
||||
msgvar.HasUnique = true
|
||||
}
|
||||
|
@ -208,22 +207,22 @@ func (pf *File) parseForMessage(line string) *MsgName {
|
|||
}
|
||||
|
||||
msgName := cases.Title(language.English, cases.NoLower).String(fields[1])
|
||||
log.Info("found messge:", msgName)
|
||||
// log.Info("found messge:", msgName)
|
||||
msg.Name = msgName
|
||||
msg.Lockname = pf.Filebase + "Mu" // this should be lowercase. do not export the Mutex
|
||||
msg.NeedIter = true
|
||||
|
||||
if strings.Contains(line, "`autogenpb:mutex`") {
|
||||
msg.DoMutex = true
|
||||
log.Info("Added Mutex=true:", msg.Name)
|
||||
// log.Info("Added Mutex=true:", msg.Name)
|
||||
}
|
||||
if strings.Contains(line, "`autogenpb:nomutex`") {
|
||||
msg.NoMutex = true
|
||||
log.Info("Added Mutex=true:", msg.Name)
|
||||
// log.Info("Added Mutex=true:", msg.Name)
|
||||
}
|
||||
if strings.Contains(line, "`autogenpb:marshal`") {
|
||||
msg.DoMarshal = true
|
||||
log.Info("Added Marshal=true:", msg.Name)
|
||||
// log.Info("Added Marshal=true:", msg.Name)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue