From ba981d6bb2f31fae2c983e81da0c654f2b4f1593 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 29 Nov 2024 11:21:56 -0600 Subject: [PATCH] only sort keys left Signed-off-by: Jeff Carr --- argv.go | 5 +++-- main.go | 20 ++++++++++---------- testautogen/Makefile | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/argv.go b/argv.go index 9c458eb..41af3c3 100644 --- a/argv.go +++ b/argv.go @@ -9,8 +9,9 @@ package main var argv args type args struct { - Base string `arg:"--base" help:"basename"` - Proto string `arg:"--proto" help:"the .proto filename"` + LoBase string `arg:"--lobase" help:"lowercase basename"` + UpBase string `arg:"--upbase" help:"uppercase basename"` + Proto string `arg:"--proto" help:"the .proto filename"` } func (a args) Description() string { diff --git a/main.go b/main.go index cf03e66..5390e9c 100644 --- a/main.go +++ b/main.go @@ -18,12 +18,6 @@ var BUILDTIME string func main() { pp := arg.MustParse(&argv) - // 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(-1) - } - // you need a proto file if argv.Proto == "" { log.Info("you must provide --proto ") @@ -35,11 +29,17 @@ func main() { os.Exit(-1) } - if ! strings.HasSuffix(argv.Proto, ".proto") { + if !strings.HasSuffix(argv.Proto, ".proto") { log.Info("protobuf", argv.Proto, "must end in .proto") os.Exit(-1) } + // you need --upbase and --lobase + if argv.UpBase == "" { + pp.WriteHelp(os.Stdout) + os.Exit(-1) + } + cmd := []string{"go", "list", "-f", "'{{.Name}}'"} result := shell.Run(cmd) @@ -50,13 +50,13 @@ func main() { protobase := strings.TrimSuffix(argv.Proto, ".proto") - f, _ := os.OpenFile(protobase + ".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600) + f, _ := os.OpenFile(protobase+".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600) sortmap := make(map[string]string) sortmap["package"] = packageName - sortmap["base"] = "gitTag" + sortmap["base"] = argv.LoBase sortmap["lock"] = sortmap["base"] + "slock" - sortmap["Base"] = "GitTag" + sortmap["Base"] = argv.UpBase sortmap["Bases"] = sortmap["Base"] + "s" sortmap["sortBy"] = "ByPath" diff --git a/testautogen/Makefile b/testautogen/Makefile index bd33133..534167e 100644 --- a/testautogen/Makefile +++ b/testautogen/Makefile @@ -6,7 +6,7 @@ test: vet all: clean test.pb.go run goimports vet run: - ../autogenpb --proto test.proto + ../autogenpb --proto test.proto --lobase gitTag --upbase GitTag vet: @GO111MODULE=off go vet