diff options
| author | Jeff Carr <[email protected]> | 2025-01-10 12:19:22 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-10 12:19:22 -0600 |
| commit | e676c213b16cf997ad43bea23229eb4878ab5b16 (patch) | |
| tree | 081f783a306f3c92ab3cf4797b158b460c850372 /main.go | |
| parent | d36344e463e80d89d0cc8b028b6243823d184b35 (diff) | |
maybe a function I can use with patchsets.proto
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 71 |
1 files changed, 37 insertions, 34 deletions
@@ -48,9 +48,34 @@ func main() { os.Exit(-1) } - f := new(File) - pb.Files = append(pb.Files, f) - f.Filename = argv.Proto + pf := new(File) + pb.Files = append(pb.Files, pf) + pf.Filename = argv.Proto + + pf.Filebase = strings.TrimSuffix(argv.Proto, ".proto") + + // parse sort & marshal options from the .proto file + // this goes through the .proto files and looks + // for `autogenpb: ` lines + if err := pb.protoParse(pf); err != nil { + log.Info("autogenpb parse error:", err) + badExit(err) + } + + if pf.Bases == nil { + badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)) + } + if pf.Base == nil { + badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)) + } + + // show the protobuf of the protobuf. It's like Inception + pf.printMsgTable() + + // if you have gotten here, at least the .proto buf file is OK + if argv.DryRun { + okExit("") + } // todo, look for go.work files if argv.GoSrc == "" { @@ -96,59 +121,37 @@ func main() { } else { packageName = argv.Package } - f.Package = packageName - - protobase := strings.TrimSuffix(argv.Proto, ".proto") - f.Filebase = protobase - - // parse sort & marshal options from the .proto file - // this goes through the .proto files and looks - // for `autogenpb: ` lines - if err := pb.protoParse(f); err != nil { - log.Info("autogenpb parse error:", err) - badExit(err) - } - - if f.Bases == nil { - badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", f.Filebase)) - } - if f.Base == nil { - badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", f.Filebase)) - } - - if argv.DryRun { - okExit("") - } + pf.Package = packageName // try to make foo.pb.go with protoc if it's not here // this is helpful because the protoc-gen-go lines // are also annoying to code by hand - f.Pbfilename = f.Filebase + ".pb.go" + pf.Pbfilename = pf.Filebase + ".pb.go" // try to create the foo.pb.go file using protoc if it is not there - if !shell.Exists(f.Pbfilename) { - if err := pb.protocBuild(f); err != nil { + if !shell.Exists(pf.Pbfilename) { + if err := pb.protocBuild(pf); err != nil { badExit(err) } } // try to add the Mutex to the pb.go file - if err := pb.addMutex(f); err != nil { + if err := pb.addMutex(pf); err != nil { badExit(err) } // if foo.pb.go still doesn't exist, protoc failed - if !shell.Exists(f.Pbfilename) { - log.Info("protoc build error.", f.Pbfilename) + if !shell.Exists(pf.Pbfilename) { + log.Info("protoc build error.", pf.Pbfilename) badExit(errors.New("failed to be created with protoc and proto-gen-go")) } // make the marshal.pb.go file - pb.marshal(f) + pb.marshal(pf) // make the sort.pb.go file - pb.makeNewSortfile(f) + pb.makeNewSortfile(pf) } func okExit(s string) { |
