diff --git a/main.go b/main.go index 3be3730..a2f8e6b 100644 --- a/main.go +++ b/main.go @@ -86,18 +86,17 @@ func main() { iterTop(f, sortmap) iterNext(f, sortmap) - // setup Append() functions - if argv.Append == "" { - iterAppend(f, sortmap) // Append() enforce no unique keys - } else { - iterAppend(f, sortmap) // Append() enforce no unique keys - sortmap["append"] = argv.Append - iterAppend(f, sortmap) // Append() enforce unique key argv.Append - } - // setup Sort() functions if len(argv.Sort) == 0 { // don't do any sorting + // setup Append() functions + if argv.Append == "" { + iterAppend(f, sortmap) // Append() enforce no unique keys + } else { + iterAppend(f, sortmap) // Append() enforce no unique keys + sortmap["append"] = argv.Append + iterAppend(f, sortmap) // Append() enforce unique key argv.Append + } } else { sortparts := strings.Split(argv.Sort[0], ",") sortmap["sortBy"] = sortparts[0] @@ -105,6 +104,16 @@ func main() { iterSort(f, sortmap) + if argv.Append == "" { + iterAppend(f, sortmap) // Append() enforce no unique keys + } else { + iterAppend(f, sortmap) // Append() enforce no unique keys + sortmap["append"] = argv.Append + iterAppend(f, sortmap) // Append() enforce unique key argv.Append + } + sortmap["append"] = sortmap["sortKey"] + iterAppend(f, sortmap) // Append() enforce unique key argv.Append + // add ReplaceKey() iterDelete(f, sortmap) iterReplace(f, sortmap) @@ -255,7 +264,7 @@ func iterAppend(w io.Writer, names map[string]string) { fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool {") } else { // fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool { // todo: make unique name here") - fmt.Fprintln(w, "func (all *"+names["Bases"]+") AppendUnique(newP *"+names["Base"]+") bool {") + fmt.Fprintln(w, "func (all *"+names["Bases"]+") AppendUnique"+names["append"]+"(newP *"+names["Base"]+") bool {") } fmt.Fprintln(w, " "+names["lock"]+".Lock()") fmt.Fprintln(w, " defer "+names["lock"]+".Unlock()") diff --git a/testautogen/Makefile b/testautogen/Makefile index a1bf723..476e3d0 100644 --- a/testautogen/Makefile +++ b/testautogen/Makefile @@ -6,8 +6,8 @@ test: vet all: clean test.pb.go forgeConfig.pb.go run run: - ../autogenpb --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" --marshal GitTags --append Refname - ../autogenpb --proto forgeConfig.proto --sort "ByPath,GoPath" --append GoPath + ../autogenpb --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" --marshal GitTags --append Subject + ../autogenpb --proto forgeConfig.proto --sort "ByPath,GoPath" # --append GoPath vet: @GO111MODULE=off go vet