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

29
main.go
View File

@ -86,18 +86,17 @@ func main() {
iterTop(f, sortmap) iterTop(f, sortmap)
iterNext(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 // setup Sort() functions
if len(argv.Sort) == 0 { if len(argv.Sort) == 0 {
// don't do any sorting // 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 { } else {
sortparts := strings.Split(argv.Sort[0], ",") sortparts := strings.Split(argv.Sort[0], ",")
sortmap["sortBy"] = sortparts[0] sortmap["sortBy"] = sortparts[0]
@ -105,6 +104,16 @@ func main() {
iterSort(f, sortmap) 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() // add ReplaceKey()
iterDelete(f, sortmap) iterDelete(f, sortmap)
iterReplace(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 {") fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool {")
} else { } 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"]+") 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, " "+names["lock"]+".Lock()")
fmt.Fprintln(w, " defer "+names["lock"]+".Unlock()") fmt.Fprintln(w, " defer "+names["lock"]+".Unlock()")

View File

@ -6,8 +6,8 @@ test: vet
all: clean test.pb.go forgeConfig.pb.go run all: clean test.pb.go forgeConfig.pb.go run
run: run:
../autogenpb --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" --marshal GitTags --append Refname ../autogenpb --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" --marshal GitTags --append Subject
../autogenpb --proto forgeConfig.proto --sort "ByPath,GoPath" --append GoPath ../autogenpb --proto forgeConfig.proto --sort "ByPath,GoPath" # --append GoPath
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet