mroe argv checks
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
28daefa6c5
commit
8158a66db5
3
Makefile
3
Makefile
|
@ -5,6 +5,9 @@ run: clean build
|
||||||
make -C testautogen/ all
|
make -C testautogen/ all
|
||||||
make -C testSort/
|
make -C testSort/
|
||||||
|
|
||||||
|
test:
|
||||||
|
./autogenpb --proto test.proto
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
@GO111MODULE=off go vet
|
@GO111MODULE=off go vet
|
||||||
@echo this go library package builds okay
|
@echo this go library package builds okay
|
||||||
|
|
22
main.go
22
main.go
|
@ -21,7 +21,23 @@ func main() {
|
||||||
// for very new users or users unfamilar with the command line, this may help them
|
// for very new users or users unfamilar with the command line, this may help them
|
||||||
if argv.Base == "help" || argv.Base == "?" {
|
if argv.Base == "help" || argv.Base == "?" {
|
||||||
pp.WriteHelp(os.Stdout)
|
pp.WriteHelp(os.Stdout)
|
||||||
os.Exit(0)
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// you need a proto file
|
||||||
|
if argv.Proto == "" {
|
||||||
|
log.Info("you must provide --proto <filename>")
|
||||||
|
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}}'"}
|
cmd := []string{"go", "list", "-f", "'{{.Name}}'"}
|
||||||
|
@ -32,7 +48,9 @@ func main() {
|
||||||
packageName = strings.Trim(packageName, "'")
|
packageName = strings.Trim(packageName, "'")
|
||||||
log.Info("packageName == ", 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 := make(map[string]string)
|
||||||
sortmap["package"] = packageName
|
sortmap["package"] = packageName
|
||||||
|
|
|
@ -6,7 +6,7 @@ test: vet
|
||||||
all: clean test.pb.go run goimports vet
|
all: clean test.pb.go run goimports vet
|
||||||
|
|
||||||
run:
|
run:
|
||||||
../autogenpb
|
../autogenpb --proto test.proto
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
@GO111MODULE=off go vet
|
@GO111MODULE=off go vet
|
||||||
|
|
Loading…
Reference in New Issue