autogenpb/newsort.go

66 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
2025-01-09 15:51:45 -06:00
"fmt"
"os"
"strings"
)
2025-01-09 15:51:45 -06:00
func (pb *Files) makeNewSortfile(pf *File) error {
f, _ := os.OpenFile(pf.Filebase+".newsort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
header(f, pf)
2025-01-09 15:29:27 -06:00
pf.syncLock(f)
2025-01-09 15:51:45 -06:00
if pf.Bases == nil {
return fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)
2025-01-09 15:29:27 -06:00
}
2025-01-09 15:51:45 -06:00
if pf.Base == nil {
return fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)
2025-01-09 15:29:27 -06:00
}
2025-01-09 15:51:45 -06:00
pf.Base.iterTop(f)
pf.Base.iterNext(f)
2025-01-09 16:18:06 -06:00
pf.appendUnique(f) // Append() enforce no unique keys
2025-01-09 15:51:45 -06:00
return nil
2025-01-09 12:54:04 -06:00
// iterSortAll(f, sortmap)
if argv.Append != "" {
sortmap["append"] = string(argv.Append)
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
}
for _, s := range uniqueKeys {
// log.Info("found unique key in .proto", s)
sortmap["sortBy"] = s
sortmap["sortKey"] = s
iterSortBy(f, sortmap)
sortmap["append"] = sortmap["sortKey"]
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
iterDelete(f, sortmap)
iterReplace(f, sortmap)
iterFind(f, sortmap)
}
for _, s := range argv.Sort {
sortparts := strings.Split(s, ",")
sortmap["sortBy"] = sortparts[0]
sortmap["sortKey"] = sortparts[1]
iterSortBy(f, sortmap)
sortmap["append"] = sortmap["sortKey"]
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
iterDelete(f, sortmap)
iterReplace(f, sortmap)
iterFind(f, sortmap)
}
iterEnd(f, sortmap)
2025-01-09 15:51:45 -06:00
return nil
}