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}
|
||||
|
||||
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
|
||||
|
|
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."`
|
||||
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"`
|
||||
|
|
18
file.proto
18
file.proto
|
@ -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 {
|
||||
|
|
2
main.go
2
main.go
|
@ -86,7 +86,9 @@ func main() {
|
|||
log.Info("autogenpb parse error:", err)
|
||||
badExit(err)
|
||||
}
|
||||
if !argv.NoFormat {
|
||||
protoReformat(argv.Proto)
|
||||
}
|
||||
|
||||
if pf.Bases == nil {
|
||||
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
|
||||
|
||||
/*
|
||||
_, junk := filepath.Split(filename)
|
||||
if junk != "SignalService.proto" {
|
||||
var allLinesIter iter.Seq[string]
|
||||
allLinesIter = makeLineIter(data)
|
||||
/* check the comment preprocessor
|
||||
log.Info("filename", filename)
|
||||
alltest := makeLineIter(data)
|
||||
// gets the max vartype and varname
|
||||
for line := range allLinesIter {
|
||||
for line := range alltest {
|
||||
newfile += fmt.Sprintln(commentPreprocessor(line))
|
||||
}
|
||||
return saveFile(filename, newfile)
|
||||
}
|
||||
saveFile(filename, newfile)
|
||||
os.Exit(-1)
|
||||
*/
|
||||
|
||||
var fmtmsg *FormatMsg
|
||||
|
@ -374,6 +372,7 @@ func formatMessage(curmsg *FormatMsg) []string {
|
|||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
for _, msg := range curmsg.Enums {
|
||||
for _, newline := range formatEnum(msg) {
|
||||
newmsg = append(newmsg, newline)
|
||||
|
@ -386,11 +385,12 @@ func formatMessage(curmsg *FormatMsg) []string {
|
|||
}
|
||||
}
|
||||
|
||||
for _, msg := range curmsg.InceptionMsgs {
|
||||
for _, newline := range formatMessage(msg) {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue