add an enum for messages
This commit is contained in:
parent
ebf856a579
commit
1b7d44ec42
4
Makefile
4
Makefile
|
@ -45,7 +45,7 @@ build:
|
||||||
cp -f autogenpb autogenpb.${BUILDTIME}
|
cp -f autogenpb autogenpb.${BUILDTIME}
|
||||||
|
|
||||||
bak:
|
bak:
|
||||||
mv -f autogenpb autogenpb.last
|
cp -f autogenpb autogenpb.last
|
||||||
|
|
||||||
redo-protobuf:
|
redo-protobuf:
|
||||||
rm -f *.pb.go
|
rm -f *.pb.go
|
||||||
|
@ -63,7 +63,7 @@ proto:
|
||||||
|
|
||||||
# use the current autogenpb
|
# use the current autogenpb
|
||||||
proto-local: bak clean
|
proto-local: bak clean
|
||||||
./autogenpb.last --proto file.proto --package main
|
./autogenpb.last --proto file.proto --package main --no-format
|
||||||
|
|
||||||
junk:
|
junk:
|
||||||
cd example; rm -f go.* *.pb.go
|
cd example; rm -f go.* *.pb.go
|
||||||
|
|
3
argv.go
3
argv.go
|
@ -19,7 +19,8 @@ type args struct {
|
||||||
Regret bool `arg:"--regret" help:"ignore needed UUID. You will eventually regret this."`
|
Regret bool `arg:"--regret" help:"ignore needed UUID. You will eventually regret this."`
|
||||||
Delete bool `arg:"--delete" help:"use delete with copy experiment"`
|
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"`
|
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"`
|
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"`
|
GoPath string `arg:"--gopath" help:"the gopath of this repo"`
|
||||||
Identify string `arg:"--identify" help:"identify file"`
|
Identify string `arg:"--identify" help:"identify file"`
|
||||||
|
|
18
file.proto
18
file.proto
|
@ -61,15 +61,21 @@ message Sort {
|
||||||
|
|
||||||
// used to auto-format protobuf files
|
// used to auto-format protobuf files
|
||||||
message FormatMsg {
|
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 maxVarname = 2; // max string length of var names
|
||||||
int64 maxVartype = 3; // max string length of var types
|
int64 maxVartype = 3; // max string length of var types
|
||||||
repeated FormatMsg inceptionMsgs = 4; // messages inside messages
|
string header = 4; // the 'message {','enum {', etc line
|
||||||
repeated FormatMsg enums = 5; // locally defined enums
|
repeated string notes = 5; // unknown lines or comments
|
||||||
repeated FormatMsg oneofs = 6; // locally defined oneofs
|
repeated FormatMsg msgs = 6; // locally defined messages and enums
|
||||||
string header = 7; // the 'message {','enum {', etc line
|
repeated string lines = 7; // the variables
|
||||||
string footer = 8; // the '}' line
|
string footer = 8; // the '}' line
|
||||||
repeated string notes = 9; // unknown lines or comments
|
Type type = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Find {
|
message Find {
|
||||||
|
|
4
main.go
4
main.go
|
@ -86,7 +86,9 @@ func main() {
|
||||||
log.Info("autogenpb parse error:", err)
|
log.Info("autogenpb parse error:", err)
|
||||||
badExit(err)
|
badExit(err)
|
||||||
}
|
}
|
||||||
protoReformat(argv.Proto)
|
if !argv.NoFormat {
|
||||||
|
protoReformat(argv.Proto)
|
||||||
|
}
|
||||||
|
|
||||||
if pf.Bases == nil {
|
if pf.Bases == nil {
|
||||||
badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase))
|
badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase))
|
||||||
|
|
|
@ -49,17 +49,15 @@ func protoReformat(filename string) error {
|
||||||
|
|
||||||
var newfile string
|
var newfile string
|
||||||
|
|
||||||
/*
|
/* check the comment preprocessor
|
||||||
_, junk := filepath.Split(filename)
|
log.Info("filename", filename)
|
||||||
if junk != "SignalService.proto" {
|
alltest := makeLineIter(data)
|
||||||
var allLinesIter iter.Seq[string]
|
// gets the max vartype and varname
|
||||||
allLinesIter = makeLineIter(data)
|
for line := range alltest {
|
||||||
// gets the max vartype and varname
|
newfile += fmt.Sprintln(commentPreprocessor(line))
|
||||||
for line := range allLinesIter {
|
}
|
||||||
newfile += fmt.Sprintln(commentPreprocessor(line))
|
saveFile(filename, newfile)
|
||||||
}
|
os.Exit(-1)
|
||||||
return saveFile(filename, newfile)
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var fmtmsg *FormatMsg
|
var fmtmsg *FormatMsg
|
||||||
|
@ -374,23 +372,25 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for _, msg := range curmsg.Enums {
|
/*
|
||||||
for _, newline := range formatEnum(msg) {
|
for _, msg := range curmsg.Enums {
|
||||||
newmsg = append(newmsg, newline)
|
for _, newline := range formatEnum(msg) {
|
||||||
|
newmsg = append(newmsg, newline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, msg := range curmsg.Oneofs {
|
for _, msg := range curmsg.Oneofs {
|
||||||
for _, newline := range formatEnum(msg) {
|
for _, newline := range formatEnum(msg) {
|
||||||
newmsg = append(newmsg, newline)
|
newmsg = append(newmsg, newline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, msg := range curmsg.InceptionMsgs {
|
for _, msg := range curmsg.Msgs {
|
||||||
for _, newline := range formatMessage(msg) {
|
for _, newline := range msg.format() {
|
||||||
newmsg = append(newmsg, newline)
|
newmsg = append(newmsg, newline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
|
||||||
for _, line := range curmsg.Lines {
|
for _, line := range curmsg.Lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
|
@ -452,6 +452,7 @@ func (it *LinesScanner) Next() string {
|
||||||
}
|
}
|
||||||
// out := commentPreprocessor(it.things[it.index-1])
|
// out := commentPreprocessor(it.things[it.index-1])
|
||||||
out := it.things[it.index-1]
|
out := it.things[it.index-1]
|
||||||
|
out = commentPreprocessor(out)
|
||||||
// return strings.TrimSpace(out)
|
// return strings.TrimSpace(out)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue