fix Append() logic

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-29 14:18:35 -06:00
parent 98b366e2df
commit 678cb67c9b
2 changed files with 21 additions and 12 deletions

19
main.go
View File

@ -86,6 +86,9 @@ func main() {
iterTop(f, sortmap)
iterNext(f, sortmap)
// 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
@ -94,10 +97,6 @@ func main() {
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
} 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()")

View File

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