summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doProto.go38
-rw-r--r--generateHeader.go8
-rw-r--r--main.go63
-rw-r--r--protoParse.go5
4 files changed, 61 insertions, 53 deletions
diff --git a/doProto.go b/doProto.go
index 91c5b90..b2a2148 100644
--- a/doProto.go
+++ b/doProto.go
@@ -23,7 +23,6 @@ import (
"github.com/go-cmd/cmd"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
- "go.wit.com/lib/protobuf/argvpb"
"go.wit.com/log"
)
@@ -37,25 +36,24 @@ func doProto(argvProto string) (string, error) {
if argv.Clean != nil {
doClean(pf.Filebase)
- argvpb.GoodExit("doClean() ran")
+ return "doClean() ran", nil
}
if argv.Mtime {
doMtime(pf.Filebase)
- argvpb.GoodExit("doClean() ran")
+ return "doClean() ran", nil
}
if argv.ReFormat {
protoReformatComments(argvProto)
// time.Sleep(5 * time.Second)
protoReformat(argvProto)
- log.Info("format done")
- okExit("")
+ return "format done", nil
}
if argv.Comments {
protoReformatComments(argvProto)
- okExit("")
+ return "comments ok?", nil
}
if argv.Regret {
@@ -64,7 +62,7 @@ func doProto(argvProto string) (string, error) {
}
if doMtime(pf.Filebase) {
- argvpb.GoodExit(pf.Filename + " did not change")
+ return pf.Filename + " did not change", nil
} else {
log.Info("ctime check: need to re-run autogenpb")
}
@@ -74,7 +72,7 @@ func doProto(argvProto string) (string, error) {
// for `autogenpb: ` lines
if err := pf.protoParse(); err != nil {
log.Info("autogenpb parse error:", err)
- badExit(err)
+ return "autogenpb parse error", err
}
if !argv.NoFormat {
@@ -82,17 +80,17 @@ func doProto(argvProto string) (string, error) {
}
if pf.Bases == nil {
- badExit(fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase))
+ return "pf.Bases == nil", 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))
+ return "pf.Base == nil", fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)
}
// if you have gotten here, at least the .proto buf file is OK
if argv.DryRun {
// show the protobuf of the protobuf. It's like Inception
pf.printMsgTable()
- okExit("")
+ return "DryRun", nil
}
// todo, look for go.work files
@@ -147,21 +145,21 @@ func doProto(argvProto string) (string, error) {
// checkCmd("protoc-gen-go")
if !fhelp.CheckProtoc() {
- badExit(fmt.Errorf("you do not have 'protoc' installed"))
+ return "protoc missing", fmt.Errorf("you do not have 'protoc' installed")
}
pf.Pbfilename = pf.Filebase + ".pb.go"
// try to create the foo.pb.go file using protoc if it is not there
if !shell.Exists(pf.Pbfilename) {
if !fhelp.CheckProtoc() {
- badExit(fmt.Errorf("you do not have 'protoc' installed"))
+ return "protoc missing", fmt.Errorf("you do not have 'protoc' installed")
}
// checkCmd("protoc")
// checkCmd("protoc-gen-go")
if err := me.pb.protocBuild(pf); err != nil {
- badExit(err)
+ return "protoc failed", err
}
}
@@ -169,13 +167,13 @@ func doProto(argvProto string) (string, error) {
// try to add the Mutex to the pb.go file
if err := me.pb.addMutex(pf); err != nil {
- badExit(err)
+ return "addMutex(pf) failed", err
}
// if foo.pb.go still doesn't exist, protoc failed
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"))
+ s := "protoc build error " + pf.Pbfilename
+ return s, errors.New("failed to be created with protoc and proto-gen-go")
}
// make the marshal.pb.go file
@@ -183,18 +181,18 @@ func doProto(argvProto string) (string, error) {
// make the sort.pb.go file
if err := me.pb.makeNewSortfile(pf); err != nil {
- badExit(err)
+ return "makeNewSortfile(pf)", err
}
if pf.DoGui {
if err := me.pb.makeGuiFile(pf); err != nil {
- badExit(err)
+ return "makeGuiFile(pf)", err
}
}
if pf.DoHTTP {
if err := me.pb.makeHTTPFile(pf); err != nil {
- badExit(err)
+ return "makeHTTPFile(pf)", err
}
}
var err error
diff --git a/generateHeader.go b/generateHeader.go
index c94b045..985bad5 100644
--- a/generateHeader.go
+++ b/generateHeader.go
@@ -76,11 +76,15 @@ func (pb *File) addNewFunc(w io.Writer) {
var VERSION string = pb.Version
if UUID == "" {
log.Info("error: UUID == ''")
- os.Exit(-1)
+ pwd, _ := os.Getwd()
+ log.Info("working directory", pwd)
+ panic("autogenpb: no UUID in .proto file: " + pb.Filename)
}
if VERSION == "" {
log.Info("error: Version == ''")
- os.Exit(-1)
+ pwd, _ := os.Getwd()
+ log.Info("working directory", pwd)
+ panic("autogenpb: no Version in .proto file: " + pb.Filename)
}
fmt.Fprintln(w, "func (x *"+STRUCT+") fixUuid() {")
fmt.Fprintln(w, " if x == nil {")
diff --git a/main.go b/main.go
index 6645fb7..ea542e3 100644
--- a/main.go
+++ b/main.go
@@ -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
}
diff --git a/protoParse.go b/protoParse.go
index 03673b6..291e2f3 100644
--- a/protoParse.go
+++ b/protoParse.go
@@ -22,7 +22,6 @@ func (pf *File) protoParse() error {
// if err := pb.hasPluralMessage(pf); err != nil {
// return err
// }
- // os.Exit(0)
uuid, version, err := fhelp.ValidProtobuf(pf.Filename)
if err != nil {
@@ -222,7 +221,9 @@ func (pf *File) parseForMessage(line string) *MsgName {
parts := strings.Split(line, "autogenpb:gu")
if len(parts) != 2 {
log.Info("len(parts) != 2", line)
- os.Exit(-1)
+ pwd, _ := os.Getwd()
+ log.Info("working directory", pwd)
+ panic("autogenpb: notsure why this check is here anymore" + pf.Filename)
}
log.Info("line =", line)
log.Info("end =", parts[1])