add an enum for messages

This commit is contained in:
Jeff Carr 2025-03-27 06:26:01 -05:00
parent ebf856a579
commit 1b7d44ec42
5 changed files with 43 additions and 33 deletions

View File

@ -45,7 +45,7 @@ build:
cp -f autogenpb autogenpb.${BUILDTIME}
bak:
mv -f autogenpb autogenpb.last
cp -f autogenpb autogenpb.last
redo-protobuf:
rm -f *.pb.go
@ -63,7 +63,7 @@ proto:
# use the current autogenpb
proto-local: bak clean
./autogenpb.last --proto file.proto --package main
./autogenpb.last --proto file.proto --package main --no-format
junk:
cd example; rm -f go.* *.pb.go

View File

@ -19,7 +19,8 @@ type args struct {
Regret bool `arg:"--regret" help:"ignore needed UUID. You will eventually regret this."`
Delete bool `arg:"--delete" help:"use delete with copy experiment"`
DryRun bool `arg:"--dry-run" help:"check the .proto syntax, but don't do anything"`
Format bool `arg:"--format" help:"only reformat the .proto file"`
Format bool `arg:"--format" help:"eformat the .proto file and exit"`
NoFormat bool `arg:"--no-format" help:"do not auto-reformat the .proto file"`
GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
GoPath string `arg:"--gopath" help:"the gopath of this repo"`
Identify string `arg:"--identify" help:"identify file"`

View File

@ -61,15 +61,21 @@ message Sort {
// used to auto-format protobuf files
message FormatMsg {
repeated string lines = 1; // keys to sort on
enum Type {
MESSAGE = 0;
ENUM = 1;
ONEOF = 2;
}
int64 depth = 1; // used to indent output
int64 maxVarname = 2; // max string length of var names
int64 maxVartype = 3; // max string length of var types
repeated FormatMsg inceptionMsgs = 4; // messages inside messages
repeated FormatMsg enums = 5; // locally defined enums
repeated FormatMsg oneofs = 6; // locally defined oneofs
string header = 7; // the 'message {','enum {', etc line
string header = 4; // the 'message {','enum {', etc line
repeated string notes = 5; // unknown lines or comments
repeated FormatMsg msgs = 6; // locally defined messages and enums
repeated string lines = 7; // the variables
string footer = 8; // the '}' line
repeated string notes = 9; // unknown lines or comments
Type type = 9;
}
message Find {

View File

@ -86,7 +86,9 @@ func main() {
log.Info("autogenpb parse error:", err)
badExit(err)
}
protoReformat(argv.Proto)
if !argv.NoFormat {
protoReformat(argv.Proto)
}
if pf.Bases == nil {
badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase))

View File

@ -49,17 +49,15 @@ func protoReformat(filename string) error {
var newfile string
/*
_, junk := filepath.Split(filename)
if junk != "SignalService.proto" {
var allLinesIter iter.Seq[string]
allLinesIter = makeLineIter(data)
// gets the max vartype and varname
for line := range allLinesIter {
newfile += fmt.Sprintln(commentPreprocessor(line))
}
return saveFile(filename, newfile)
}
/* check the comment preprocessor
log.Info("filename", filename)
alltest := makeLineIter(data)
// gets the max vartype and varname
for line := range alltest {
newfile += fmt.Sprintln(commentPreprocessor(line))
}
saveFile(filename, newfile)
os.Exit(-1)
*/
var fmtmsg *FormatMsg
@ -374,23 +372,25 @@ func formatMessage(curmsg *FormatMsg) []string {
}
*/
for _, msg := range curmsg.Enums {
for _, newline := range formatEnum(msg) {
newmsg = append(newmsg, newline)
/*
for _, msg := range curmsg.Enums {
for _, newline := range formatEnum(msg) {
newmsg = append(newmsg, newline)
}
}
}
for _, msg := range curmsg.Oneofs {
for _, newline := range formatEnum(msg) {
newmsg = append(newmsg, newline)
for _, msg := range curmsg.Oneofs {
for _, newline := range formatEnum(msg) {
newmsg = append(newmsg, newline)
}
}
}
for _, msg := range curmsg.InceptionMsgs {
for _, newline := range formatMessage(msg) {
newmsg = append(newmsg, newline)
for _, msg := range curmsg.Msgs {
for _, newline := range msg.format() {
newmsg = append(newmsg, newline)
}
}
}
*/
for _, line := range curmsg.Lines {
line = strings.TrimSpace(line)
@ -452,6 +452,7 @@ func (it *LinesScanner) Next() string {
}
// out := commentPreprocessor(it.things[it.index-1])
out := it.things[it.index-1]
out = commentPreprocessor(out)
// return strings.TrimSpace(out)
return out
}