summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-28 08:19:59 -0500
committerJeff Carr <[email protected]>2025-03-28 08:19:59 -0500
commit11ccc557feda86273dc67779a1a2b45723ada3e4 (patch)
tree95f2262dc19acace1d0ab7cafa9cc8540ea20978
parentdfe42d8d2358e1437b1b086bbc420f3ffef9b46e (diff)
closer to back to working again
-rw-r--r--example/Makefile4
-rw-r--r--main.go4
-rw-r--r--protoReformat.go70
3 files changed, 25 insertions, 53 deletions
diff --git a/example/Makefile b/example/Makefile
index 2947745..06b3cdb 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -110,7 +110,7 @@ proto-reformat-comments:
../autogenpb --proto signal.proto --format-comments
proto-reformat-full:
- autogenpb --proto signal.proto --format
+ ../autogenpb --proto signal.proto --format
proto-reformat-fruit:
- autogenpb --proto fruit.proto --format
+ ../autogenpb --proto fruit.proto --format
diff --git a/main.go b/main.go
index b57c924..2c6f33e 100644
--- a/main.go
+++ b/main.go
@@ -18,7 +18,6 @@ import (
"os"
"path/filepath"
"strings"
- "time"
"github.com/alexflint/go-arg"
"github.com/go-cmd/cmd"
@@ -65,8 +64,9 @@ func main() {
if argv.Format {
protoReformatComments(argv.Proto)
- time.Sleep(5 * time.Second)
+ // time.Sleep(5 * time.Second)
protoReformat(argv.Proto)
+ log.Info("format done")
okExit("")
}
if argv.Comments {
diff --git a/protoReformat.go b/protoReformat.go
index 664e792..c2296b0 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -127,29 +127,16 @@ func protoReformat(filename string) error {
if strings.HasPrefix(line, "oneof ") {
newmsg := basemsg.newOneofMessage(line)
- newmsg.msgPB.Notes = strings.Split(comments, "\n")
+ newmsg.Notes = strings.Split(comments, "\n")
newmsg.load()
- basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
- /*
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
- */
inMessage = true
continue
}
if strings.HasPrefix(line, "enum ") {
newmsg := basemsg.newEnumMessage(line)
- newmsg.msgPB.Notes = strings.Split(comments, "\n")
+ newmsg.Notes = strings.Split(comments, "\n")
newmsg.load()
- basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
- // loadEnumDefinition(newmsg)
- /*
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
- */
inMessage = true
continue
}
@@ -158,14 +145,8 @@ func protoReformat(filename string) error {
log.Info("got to message", line)
newmsg := basemsg.newStdMessage(line)
- newmsg.msgPB.Notes = strings.Split(comments, "\n")
+ newmsg.Notes = strings.Split(comments, "\n")
newmsg.load()
- basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
- /*
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
- */
inMessage = true
continue
}
@@ -209,37 +190,28 @@ func newDepth(fmtmsg *FormatMsg, header string) *FormatMsg {
}
// func newStdMessage(fmtmsg *FormatMsg, header string) *StdMessage {
-func (msgPB *FormatMsg) newStdMessage(header string) *StdMessage {
+func (msgPB *FormatMsg) newStdMessage(header string) *FormatMsg {
newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_MESSAGE
msgPB.Msgs = append(msgPB.Msgs, newmsg)
- newstd := new(StdMessage)
- newstd.msgPB = newmsg
-
- return newstd
+ return newmsg
}
-func (msgPB *FormatMsg) newOneofMessage(header string) *StdMessage {
+func (msgPB *FormatMsg) newOneofMessage(header string) *FormatMsg {
newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_ONEOF
msgPB.Msgs = append(msgPB.Msgs, newmsg)
- newstd := new(StdMessage)
- newstd.msgPB = newmsg
-
- return newstd
+ return newmsg
}
-func (msgPB *FormatMsg) newEnumMessage(header string) *EnumMessage {
+func (msgPB *FormatMsg) newEnumMessage(header string) *FormatMsg {
newmsg := newDepth(msgPB, header)
newmsg.Type = FormatMsg_ENUM
msgPB.Msgs = append(msgPB.Msgs, newmsg)
- newstd := new(EnumMessage)
- newstd.msgPB = newmsg
-
- return newstd
+ return newmsg
}
// proto files can be defined as trees
@@ -247,36 +219,34 @@ func (msgPB *FormatMsg) newEnumMessage(header string) *EnumMessage {
// func (newMsg *EnumMessage) load() {
// func (msg *StdMessage) loadMsgDefinition(msg *StdMessage) {
func (msg *StdMessage) load() {
+ msg.msgPB.load()
+}
+
+func (msg *FormatMsg) load() {
// fmtmsg := msg.msgPB
- curPB := msg.msgPB
for allTheLines.Scan() {
line := allTheLines.Next()
if strings.HasPrefix(line, "oneof ") {
- newmsg := msg.msgPB.newOneofMessage(line)
+ newmsg := msg.newOneofMessage(line)
newmsg.load()
- // curPB = newmsg.msgPB
continue
}
if strings.HasPrefix(line, "enum ") {
- newmsg := msg.msgPB.newEnumMessage(line)
+ newmsg := msg.newEnumMessage(line)
newmsg.load()
- // curPB = newmsg.msgPB
- // loadEnumDefinition(newmsg)
continue
}
if strings.HasPrefix(line, "message ") {
// message inception. search for the architect. don't forget your totem
- newmsg := msg.msgPB.newStdMessage(line)
+ newmsg := msg.newStdMessage(line)
newmsg.load()
- // curPB = newmsg.msgPB
continue
}
if strings.HasPrefix(line, "}") {
- msg.msgPB.Footer = line
+ msg.Footer = line
return
}
- curPB.Lines = append(curPB.Lines, line)
- // fmtmsg.Lines = append(fmtmsg.Lines, line)
+ msg.Lines = append(msg.Lines, line)
}
return
@@ -425,7 +395,9 @@ func formatMessage(curmsg *FormatMsg) []string {
}
newmsg = append(newmsg, line) // " //header")
} else {
- newmsg = append(newmsg, "// ERROR: header was blank") // +" //header")
+ if curmsg.Depth != 0 {
+ newmsg = append(newmsg, "// ERROR: header was blank") // +" //header")
+ }
}
// find the max length of varname and vartype