parse out the uuid and version

This commit is contained in:
Jeff Carr 2025-01-17 02:51:16 -06:00
parent 2329bc364e
commit 45c3bd3e16
1 changed files with 45 additions and 5 deletions

View File

@ -64,9 +64,12 @@ func ValidProtobuf(filename string) (string, string, error) {
return "", "", fmt.Errorf("proto file does not have a UUID") return "", "", fmt.Errorf("proto file does not have a UUID")
} }
// ok, uuid is here // ok, uuid is here
UUID := line UUID := parseUuid(line)
log.Info("found UUID:", line) if UUID == "" {
noUuidExit(filename)
return "", "", fmt.Errorf("proto file does not have a UUID")
}
log.Info("found UUID:", UUID)
scanner.Scan() scanner.Scan()
line = scanner.Text() line = scanner.Text()
fields = strings.Fields(line) fields = strings.Fields(line)
@ -76,8 +79,12 @@ func ValidProtobuf(filename string) (string, string, error) {
return "", "", fmt.Errorf("proto file does not have a version") return "", "", fmt.Errorf("proto file does not have a version")
} }
// found "version", the .proto file conforms // found "version", the .proto file conforms
version := line version := parseVersion(line)
log.Info("found Version:", line) if version == "" {
noUuidExit(filename)
return "", "", fmt.Errorf("proto file does not have a version")
}
log.Info("found Version:", version)
return UUID, version, nil return UUID, version, nil
} }
// right now, noPluralMessage does os.Exit(-1) // right now, noPluralMessage does os.Exit(-1)
@ -85,6 +92,32 @@ func ValidProtobuf(filename string) (string, string, error) {
return "", "", fmt.Errorf("proto file does not have message %s", pluralBase) return "", "", fmt.Errorf("proto file does not have message %s", pluralBase)
} }
func parseUuid(line string) string {
fields := strings.Split(line, "autogenpb:uuid:")
if len(fields) < 2 {
return ""
}
end := fields[1]
fields = strings.Fields(end)
uuid := fields[0]
uuid = strings.Trim(uuid, "`")
// log.Info("fhelp.parseUuid() uuid =", uuid)
return uuid
}
func parseVersion(line string) string {
fields := strings.Split(line, "autogenpb:version:")
if len(fields) < 2 {
return ""
}
end := fields[1]
fields = strings.Fields(end)
ver := fields[0]
ver = strings.Trim(ver, "`")
// log.Info("fhelp.parseVersion() ver =", ver)
return ver
}
func noPluralMessageExit(filename string) { func noPluralMessageExit(filename string) {
filebase := strings.TrimSuffix(filename, ".proto") filebase := strings.TrimSuffix(filename, ".proto")
base := cases.Title(language.English, cases.NoLower).String(filebase) base := cases.Title(language.English, cases.NoLower).String(filebase)
@ -129,7 +162,14 @@ func noUuidExit(filename string) {
log.Info("") log.Info("")
log.Info("If you don't have a UUID, you can use the randomly generated one here") log.Info("If you don't have a UUID, you can use the randomly generated one here")
log.Info("") log.Info("")
log.Info("If you wish to ignore this, set PROTOBUF_REGRET=true")
log.Info("You will probably regret not trying to follow the standard here. This format is used as a 'handshake'.")
log.Info("###########################################################################") log.Info("###########################################################################")
if os.Getenv("PROTOBUF_REGRET") == "true" {
log.Info("PROTOBUF_REGRET=true was set")
log.Info("###########################################################################")
return
}
badExit(fmt.Errorf("proto file error %s", filename)) badExit(fmt.Errorf("proto file error %s", filename))
} }