summaryrefslogtreecommitdiff
path: root/protoParse.go
diff options
context:
space:
mode:
Diffstat (limited to 'protoParse.go')
-rw-r--r--protoParse.go62
1 files changed, 7 insertions, 55 deletions
diff --git a/protoParse.go b/protoParse.go
index 9efe2fd..72c7e17 100644
--- a/protoParse.go
+++ b/protoParse.go
@@ -3,68 +3,17 @@ package main
// auto run protoc with the correct args
import (
- "bufio"
- "fmt"
"os"
"strings"
"go.wit.com/lib/fhelp"
- "go.wit.com/log"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
// this parses the .proto file and handles anything with `autogenpb: `
-// does the fruit.proto file have "message Fruits"
-func (pb *Files) hasPluralMessage(f *File) error {
- file, err := os.Open(f.Filename)
- if err != nil {
- return err
- }
- defer file.Close()
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- line := scanner.Text()
-
- base := cases.Title(language.English, cases.NoLower).String(f.Filebase)
- prefix := "message " + base + "s {" // to conform, it must have an added 's'
- if !strings.HasPrefix(line, prefix) {
- // log.Info("nope", prefix, "line", line)
- // nope, not this line
- 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")
- }
- // ok, uuid is here
- 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")
- }
- // found "version", the .proto file conforms
- f.Version = line
- log.Info("found Version:", line)
- return nil
- }
- f.noPluralMessage()
- return fmt.Errorf("proto file error %s", f.Filename)
-}
-
-func (pb *Files) protoParse(pf *File) error {
+func (pf *File) protoParse() error {
// does the file conform to the standard? (also reads in UUID & Version)
// if err := pb.hasPluralMessage(pf); err != nil {
// return err
@@ -73,10 +22,13 @@ func (pb *Files) protoParse(pf *File) error {
uuid, version, err := fhelp.ValidProtobuf(pf.Filename)
if err != nil {
- return err
+ // the user can bypass this, but it's probably not worth allowing this
+ if os.Getenv("PROTOBUF_REGRET") != "true" {
+ return err
+ }
}
- pb.Uuid = uuid
- pb.Version = version
+ pf.Uuid = uuid
+ pf.Version = version
// read in the .proto file
data, err := os.ReadFile(pf.Filename)