use string map

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-29 10:23:50 -06:00
parent fb79d5b17d
commit 6c425fc05e
1 changed files with 6 additions and 6 deletions

12
main.go
View File

@ -23,7 +23,7 @@ func main() {
header(f, "testautogen") header(f, "testautogen")
syncLock(f, "gitTagslock") syncLock(f, "gitTagslock")
iterTop(f, "GitTag") iterTop(f, "GitTag")
iterNext(f, "GitTag") iterNext(f)
iterSort(f) iterSort(f)
iterAppend(f) iterAppend(f)
iterEnd(f) iterEnd(f)
@ -80,9 +80,9 @@ func iterTop(w io.Writer, name string) {
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
} }
func iterNext(w io.Writer, name string) { func iterNext(w io.Writer) {
fmt.Fprintln(w, "// Next() returns the next thing in the array") fmt.Fprintln(w, "// Next() returns the next thing in the array")
fmt.Fprintln(w, "func (it *" + name + "Iterator) Next() *" + name + " {") fmt.Fprintln(w, "func (it *" + names["Base"] + "Iterator) Next() *" + names["Base"] + " {")
fmt.Fprintln(w, " if it.packs[it.index-1] == nil {") fmt.Fprintln(w, " if it.packs[it.index-1] == nil {")
fmt.Fprintln(w, " for i, d := range it.packs {") fmt.Fprintln(w, " for i, d := range it.packs {")
fmt.Fprintln(w, " fmt.Println(\"i =\", i, d)") fmt.Fprintln(w, " fmt.Println(\"i =\", i, d)")
@ -149,17 +149,17 @@ func iterEnd(w io.Writer) {
func iterAppend(w io.Writer) { func iterAppend(w io.Writer) {
fmt.Fprintln(w, "// enforces no duplicate Refname names") fmt.Fprintln(w, "// enforces no duplicate Refname names")
fmt.Fprintln(w, "func (all *GitTags) Append(newP *GitTag) bool {") fmt.Fprintln(w, "func (all *" + names["Bases"] + ") 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()")
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
fmt.Fprintln(w, " for _, p := range all.GitTags {") fmt.Fprintln(w, " for _, p := range all." + names["Bases"] + " {")
fmt.Fprintln(w, " if p.Refname == newP.Refname {") fmt.Fprintln(w, " if p.Refname == newP.Refname {")
fmt.Fprintln(w, " return false") fmt.Fprintln(w, " return false")
fmt.Fprintln(w, " }") fmt.Fprintln(w, " }")
fmt.Fprintln(w, " }") fmt.Fprintln(w, " }")
fmt.Fprintln(w, "") fmt.Fprintln(w, "")
fmt.Fprintln(w, " all.GitTags = append(all.GitTags, newP)") fmt.Fprintln(w, " all." + names["Bases"] + " = append(all." + names["Bases"] + ", newP)")
fmt.Fprintln(w, " return true") fmt.Fprintln(w, " return true")
fmt.Fprintln(w, "}") fmt.Fprintln(w, "}")
fmt.Fprintln(w, "") fmt.Fprintln(w, "")