summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--argv.go2
-rw-r--r--main.go20
-rw-r--r--testautogen/Makefile2
4 files changed, 19 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 7939343..c6d6a61 100644
--- a/Makefile
+++ b/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
diff --git a/argv.go b/argv.go
index 41af3c3..fb1eedd 100644
--- a/argv.go
+++ b/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 {
diff --git a/main.go b/main.go
index 5390e9c..1f0f6b9 100644
--- a/main.go
+++ b/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)
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