summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go40
1 files changed, 22 insertions, 18 deletions
diff --git a/main.go b/main.go
index 2e71346..f07182b 100644
--- a/main.go
+++ b/main.go
@@ -35,10 +35,9 @@ var ARGNAME string = "autogenpb"
// var fsort *os.File // the sort.pb.go output file
func main() {
- auto := prep.Bash(&argv) // add support for bash autocomplete with go-arg
-
- var pb *Files
- pb = new(Files)
+ me = new(mainType)
+ me.sh = prep.Bash(&argv) // add support for bash autocomplete with go-arg
+ me.pb = new(Files)
if argv.Identify != "" {
if err := doIdentify(argv.Identify); err != nil {
@@ -50,7 +49,7 @@ func main() {
// you need a proto file
if argv.Proto == "" {
log.Info("you must provide --proto <filename>")
- auto.WriteHelp()
+ me.sh.WriteHelp()
os.Exit(-1)
}
@@ -64,15 +63,19 @@ func main() {
os.Exit(-1)
}
+ doProto(argv.Proto)
+}
+
+func doProto(argvProto string) error {
if argv.Format {
- protoReformatComments(argv.Proto)
+ protoReformatComments(argvProto)
// time.Sleep(5 * time.Second)
- protoReformat(argv.Proto)
+ protoReformat(argvProto)
log.Info("format done")
okExit("")
}
if argv.Comments {
- protoReformatComments(argv.Proto)
+ protoReformatComments(argvProto)
okExit("")
}
@@ -82,11 +85,11 @@ func main() {
}
pf := new(File)
- pb.Files = append(pb.Files, pf)
- pf.Filename = argv.Proto
+ me.pb.Files = append(me.pb.Files, pf)
+ pf.Filename = argvProto
pf.IterMap = make(map[string]string)
- pf.Filebase = strings.TrimSuffix(argv.Proto, ".proto")
+ pf.Filebase = strings.TrimSuffix(argvProto, ".proto")
// parse sort & marshal options from the .proto file
// this goes through the .proto files and looks
@@ -97,7 +100,7 @@ func main() {
}
if !argv.NoFormat {
- protoReformat(argv.Proto)
+ protoReformat(argvProto)
}
if pf.Bases == nil {
@@ -179,7 +182,7 @@ func main() {
// checkCmd("protoc")
// checkCmd("protoc-gen-go")
- if err := pb.protocBuild(pf); err != nil {
+ if err := me.pb.protocBuild(pf); err != nil {
badExit(err)
}
@@ -187,7 +190,7 @@ func main() {
os.Chdir(startpwd)
// try to add the Mutex to the pb.go file
- if err := pb.addMutex(pf); err != nil {
+ if err := me.pb.addMutex(pf); err != nil {
badExit(err)
}
@@ -198,27 +201,28 @@ func main() {
}
// make the marshal.pb.go file
- pb.marshal(pf)
+ me.pb.marshal(pf)
// make the sort.pb.go file
- if err := pb.makeNewSortfile(pf); err != nil {
+ if err := me.pb.makeNewSortfile(pf); err != nil {
badExit(err)
}
if pf.DoGui {
- if err := pb.makeGuiFile(pf); err != nil {
+ if err := me.pb.makeGuiFile(pf); err != nil {
badExit(err)
}
}
if pf.DoHTTP {
- if err := pb.makeHTTPFile(pf); err != nil {
+ if err := me.pb.makeHTTPFile(pf); err != nil {
badExit(err)
}
}
log.Info("")
log.Info("you may have to run 'goimport -w *.go' on the new *pb.go files")
log.Info("")
+ return nil
}
func okExit(s string) {