summaryrefslogtreecommitdiff
path: root/protoParse.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-12 06:13:42 -0600
committerJeff Carr <[email protected]>2025-01-12 06:13:42 -0600
commit08cd2afd86557f06d6b3f6e006d686fef4c7b2ee (patch)
tree5bff830418741290f2e13502e8137fb877a01999 /protoParse.go
parent5b4491f17ba4325ab9783374d4efa7e4aa652a9f (diff)
adding help
Diffstat (limited to 'protoParse.go')
-rw-r--r--protoParse.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/protoParse.go b/protoParse.go
index 2cefc80..c18c87d 100644
--- a/protoParse.go
+++ b/protoParse.go
@@ -37,6 +37,7 @@ func (pb *Files) hasPluralMessage(f *File) error {
line = scanner.Text()
fields := strings.Fields(line)
if fields[0] == "string" && fields[1] != "uuid" {
+ f.noUuid()
return fmt.Errorf("proto file does not have a UUID")
}
// ok, uuid is here
@@ -46,6 +47,7 @@ func (pb *Files) hasPluralMessage(f *File) error {
line = scanner.Text()
fields = strings.Fields(line)
if fields[0] == "string" && fields[1] != "version" {
+ f.noUuid()
return fmt.Errorf("proto file does not have a version")
}
// found "version", the .proto file conforms
@@ -53,9 +55,55 @@ func (pb *Files) hasPluralMessage(f *File) error {
log.Info("found Version:", line)
return nil
}
+ f.noPluralMessage()
return fmt.Errorf("proto file error %s", f.Filename)
}
+func (pf *File) noPluralMessage() {
+ base := cases.Title(language.English, cases.NoLower).String(pf.Filebase)
+
+ log.Info("")
+ log.Info("###########################################################################")
+ log.Info("Your proto file", pf.Filename, "does not contain the correct 'message' definitions")
+ log.Info("")
+ log.Info("For autogenpb to work on your file", pf.Filename, ", you must have both names exactly:")
+ log.Info("")
+ log.Printf("message %s {\n", base)
+ log.Info("}")
+ log.Printf("message %s {\n", base+"s")
+ log.Info("}")
+ log.Info("")
+ log.Info("###########################################################################")
+ badExit(fmt.Errorf("proto file error %s", pf.Filename))
+}
+
+// message Fruits { // `autogenpb:marshal` `autogenpb:mutex`
+// string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
+// string version = 2; // `autogenpb:version:v0.0.1`
+// repeated Fruit Fruits = 3; // THIS MUST BE "Fruit" and then "Fruit" + "s"
+// }
+
+func (pf *File) noUuid() {
+ base := cases.Title(language.English, cases.NoLower).String(pf.Filebase)
+
+ log.Info("")
+ log.Info("###########################################################################")
+ log.Info("Your proto file", pf.Filename, "is incorrect for 'message' ", base+"s")
+ 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(" string version = 2; // `autogenpb:version:v0.0.1`")
+ log.Info(" repeated Fruit Fruits = 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")
+ log.Info("")
+ log.Info("###########################################################################")
+ badExit(fmt.Errorf("proto file error %s", pf.Filename))
+}
+
func (pb *Files) protoParse(pf *File) error {
// does the file conform to the standard? (also reads in UUID & Version)
if err := pb.hasPluralMessage(pf); err != nil {