maybe this will be useful. don't know
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
ba981d6bb2
commit
07e556e379
2
Makefile
2
Makefile
|
@ -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
|
||||
|
|
2
argv.go
2
argv.go
|
@ -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 {
|
||||
|
|
20
main.go
20
main.go
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue