diff options
| author | Jeff Carr <[email protected]> | 2024-11-29 11:32:27 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-29 11:32:27 -0600 |
| commit | 07e556e3799f815958c7c097686d6ba7176bbe33 (patch) | |
| tree | 177657acc18eb928ccc646d09b6a237d85d764f4 | |
| parent | ba981d6bb2f31fae2c983e81da0c654f2b4f1593 (diff) | |
maybe this will be useful. don't know
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | argv.go | 2 | ||||
| -rw-r--r-- | main.go | 20 | ||||
| -rw-r--r-- | testautogen/Makefile | 2 |
4 files changed, 19 insertions, 7 deletions
@@ -6,7 +6,7 @@ run: clean build make -C testSort/ test: - ./autogenpb --proto test.proto + ./autogenpb --dry-run --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" vet: @GO111MODULE=off go vet @@ -12,6 +12,8 @@ type args struct { LoBase string `arg:"--lobase" help:"lowercase basename"` UpBase string `arg:"--upbase" help:"uppercase basename"` Proto string `arg:"--proto" help:"the .proto filename"` + Sort []string `arg:"--sort" help:"how and what to sort on"` + DryRun bool `arg:"--dry-run" help:"show what would be run"` } func (a args) Description() string { @@ -26,7 +26,9 @@ func main() { if !shell.Exists(argv.Proto) { log.Info("protobuf", argv.Proto, "is missing") - os.Exit(-1) + if ! argv.DryRun { + os.Exit(-1) + } } if !strings.HasSuffix(argv.Proto, ".proto") { @@ -50,8 +52,6 @@ func main() { 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 sortmap["base"] = argv.LoBase @@ -59,8 +59,18 @@ func main() { sortmap["Base"] = argv.UpBase sortmap["Bases"] = sortmap["Base"] + "s" - sortmap["sortBy"] = "ByPath" - sortmap["sortKey"] = "Refname" + sortparts := strings.Split(argv.Sort[0], ",") + sortmap["sortBy"] = sortparts[0] + sortmap["sortKey"] = sortparts[1] + + if argv.DryRun { + for k, v := range sortmap { + log.Info(k, "=", v) + } + os.Exit(0) + } + + f, _ := os.OpenFile(protobase+".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600) header(f, sortmap) syncLock(f, sortmap) diff --git a/testautogen/Makefile b/testautogen/Makefile index 534167e..4cde6ea 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 --lobase gitTag --upbase GitTag + ../autogenpb --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" vet: @GO111MODULE=off go vet |
