summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/bad.proto6
-rw-r--r--protoParse.go13
2 files changed, 13 insertions, 6 deletions
diff --git a/example/bad.proto b/example/bad.proto
index b9198e7..5c73c1b 100644
--- a/example/bad.proto
+++ b/example/bad.proto
@@ -9,8 +9,8 @@ message Bad {
string something = 1;
}
-message Badthing {
+message Badss {
string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
- string version = 2; // `autogenpb:version:v0.0.1`
- repeated Bad Bads = 3;
+ string versions = 2; // `autogenpb:version:v0.0.1`
+ repeated Bad Badss = 3;
}
diff --git a/protoParse.go b/protoParse.go
index c18c87d..1e4cf79 100644
--- a/protoParse.go
+++ b/protoParse.go
@@ -11,6 +11,8 @@ import (
"go.wit.com/log"
"golang.org/x/text/cases"
"golang.org/x/text/language"
+
+ "github.com/google/uuid"
)
// this parses the .proto file and handles anything with `autogenpb: `
@@ -34,8 +36,10 @@ func (pb *Files) hasPluralMessage(f *File) error {
continue
}
+ scanner.Scan()
line = scanner.Text()
fields := strings.Fields(line)
+ // log.Info("GOT LINE", line)
if fields[0] == "string" && fields[1] != "uuid" {
f.noUuid()
return fmt.Errorf("proto file does not have a UUID")
@@ -44,8 +48,10 @@ func (pb *Files) hasPluralMessage(f *File) error {
f.Uuid = line
log.Info("found UUID:", line)
+ scanner.Scan()
line = scanner.Text()
fields = strings.Fields(line)
+ // log.Info("GOT LINE", line)
if fields[0] == "string" && fields[1] != "version" {
f.noUuid()
return fmt.Errorf("proto file does not have a version")
@@ -85,6 +91,7 @@ func (pf *File) noPluralMessage() {
func (pf *File) noUuid() {
base := cases.Title(language.English, cases.NoLower).String(pf.Filebase)
+ id := uuid.New()
log.Info("")
log.Info("###########################################################################")
@@ -92,10 +99,10 @@ func (pf *File) noUuid() {
log.Info("")
log.Info("For autogenpb to work on your file", pf.Filename, ",", base+"s must be exactly:")
log.Info("")
- log.Info("message Fruits { // `autogenpb:marshal` `autogenpb:mutex`")
- log.Info(" string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`")
+ log.Info("message", base+"s", "{ // `autogenpb:marshal` `autogenpb:mutex`")
+ log.Info(" string uuid = 1; // `autogenpb:uuid:" + id.String() + "`")
log.Info(" string version = 2; // `autogenpb:version:v0.0.1`")
- log.Info(" repeated Fruit Fruits = 3; // THIS MUST BE ", base, " and then ", base+"s")
+ log.Info(" repeated", base, base+"s", " = 3; // THIS MUST BE ", base, " and then ", base+"s")
log.Info("}")
log.Info("")
log.Info("If you don't have a UUID, you can use the randomly generated one here")