diff --git a/Makefile b/Makefile index 02f0903..7939343 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ run: clean build make -C testautogen/ all make -C testSort/ +test: + ./autogenpb --proto test.proto + vet: @GO111MODULE=off go vet @echo this go library package builds okay diff --git a/main.go b/main.go index 0de13f3..cf03e66 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,23 @@ func main() { // for very new users or users unfamilar with the command line, this may help them if argv.Base == "help" || argv.Base == "?" { pp.WriteHelp(os.Stdout) - os.Exit(0) + os.Exit(-1) + } + + // you need a proto file + if argv.Proto == "" { + log.Info("you must provide --proto ") + os.Exit(-1) + } + + if !shell.Exists(argv.Proto) { + log.Info("protobuf", argv.Proto, "is missing") + os.Exit(-1) + } + + if ! strings.HasSuffix(argv.Proto, ".proto") { + log.Info("protobuf", argv.Proto, "must end in .proto") + os.Exit(-1) } cmd := []string{"go", "list", "-f", "'{{.Name}}'"} @@ -32,7 +48,9 @@ func main() { packageName = strings.Trim(packageName, "'") log.Info("packageName == ", packageName) - f, _ := os.OpenFile("test.sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600) + protobase := strings.TrimSuffix(argv.Proto, ".proto") + + f, _ := os.OpenFile(protobase + ".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600) sortmap := make(map[string]string) sortmap["package"] = packageName diff --git a/testautogen/Makefile b/testautogen/Makefile index 749686c..bd33133 100644 --- a/testautogen/Makefile +++ b/testautogen/Makefile @@ -6,7 +6,7 @@ test: vet all: clean test.pb.go run goimports vet run: - ../autogenpb + ../autogenpb --proto test.proto vet: @GO111MODULE=off go vet