diff options
| author | Jeff Carr <[email protected]> | 2025-10-30 23:15:34 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-30 23:15:34 -0500 |
| commit | 01cd36974b1f38264d2ff56b8c03c5103b78612c (patch) | |
| tree | d900e70155d18592888433b2c2e50c8c2be2871d /main.go | |
| parent | 8bc73bdc2d7b22ee4f21bf878bbca947f6a1b57a (diff) | |
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 63 |
1 files changed, 34 insertions, 29 deletions
@@ -15,7 +15,8 @@ package main import ( "errors" - "os" + "fmt" + "path/filepath" "strings" "go.wit.com/lib/fhelp" @@ -35,12 +36,33 @@ func main() { err = doIdentify(argv.Identify) } - // check if it's ok to run autogenpb - s, err = doPrecheck() - - if err == nil { - // it's safe to run - s, err = doProto(argv.Proto) + if argv.Proto == "" { + // try to process every .proto file + globPattern := "*.proto" + var files []string + files, err = filepath.Glob(globPattern) + if err != nil { + fmt.Println("glob error", err, files) + } + if len(files) == 0 { + err = errors.New("autogenpb found no .proto files") + } else { + for _, file := range files { + fmt.Println("checking protobuf file:", file) + s, err = doProto(file) + if err != nil { + break + } + } + } + } else { + // user is trying a specific proto file + // check if it's ok to run autogenpb + s, err = doPrecheck(argv.Proto) + if err == nil { + // it's safe to run + s, err = doProto(argv.Proto) + } } // safe exits back to your shell (with timing and toolkit close) @@ -50,35 +72,18 @@ func main() { argvpb.GoodExit(s) } -func okExit(s string) { - log.Info("autogenpb ok", s) - os.Exit(0) -} - -func badExit(err error) { - log.Info("autogenpb error:", err) - os.Exit(-1) -} - -func doPrecheck() (string, error) { +func doPrecheck(protofile string) (string, error) { var s string var err error - // you need a proto file - if argv.Proto == "" { - // todo: run on every .proto file - log.Info("todo: run on all .proto files") - me.pp.WriteHelp(os.Stdout) - return "you must provide --proto <protoname>.proto", errors.New("need .proto") - } - if !shell.Exists(argv.Proto) { - s = log.Sprintf("protobuf %s is missing", argv.Proto) + if !shell.Exists(protofile) { + s = log.Sprintf("protobuf %s is missing", protofile) return "missing file", errors.New(s) } - if !strings.HasSuffix(argv.Proto, ".proto") { + if !strings.HasSuffix(protofile, ".proto") { s = "wrote filetype" - err = errors.New(log.Sprintf("protobuf %s doesn't end in '.proto'", argv.Proto)) + err = errors.New(log.Sprintf("protobuf %s doesn't end in '.proto'", protofile)) return s, err } |
