mroe argv checks

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-29 11:15:40 -06:00
parent 28daefa6c5
commit 8158a66db5
3 changed files with 24 additions and 3 deletions

View File

@ -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

22
main.go
View File

@ -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 <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}}'"}
@ -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

View File

@ -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