maybe this will be useful. don't know

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-29 11:32:27 -06:00
parent ba981d6bb2
commit 07e556e379
4 changed files with 19 additions and 7 deletions

View File

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

View File

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

18
main.go
View File

@ -26,8 +26,10 @@ func main() {
if !shell.Exists(argv.Proto) {
log.Info("protobuf", argv.Proto, "is missing")
if ! argv.DryRun {
os.Exit(-1)
}
}
if !strings.HasSuffix(argv.Proto, ".proto") {
log.Info("protobuf", argv.Proto, "must end in .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)

View File

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