diff options
| author | Jeff Carr <[email protected]> | 2025-01-17 02:50:36 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-17 02:50:36 -0600 |
| commit | 0a4b985020eab6b2ca088f7784830c7103f067e4 (patch) | |
| tree | 256133d1ca5a65ca110f6efd4f99899ff4278afe /protoParse.go | |
| parent | 97c65be0a0bdadca494956fd9c2b58d94e8a5fcc (diff) | |
start saving and setting the Uuidv0.0.45
Diffstat (limited to 'protoParse.go')
| -rw-r--r-- | protoParse.go | 62 |
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) |
