make some help on the correct messages needed

This commit is contained in:
Jeff Carr 2025-01-12 06:28:12 -06:00
parent 08cd2afd86
commit 721bbd8f92
2 changed files with 13 additions and 6 deletions

View File

@ -9,8 +9,8 @@ message Bad {
string something = 1; string something = 1;
} }
message Badthing { message Badss {
string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079` string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
string version = 2; // `autogenpb:version:v0.0.1` string versions = 2; // `autogenpb:version:v0.0.1`
repeated Bad Bads = 3; repeated Bad Badss = 3;
} }

View File

@ -11,6 +11,8 @@ import (
"go.wit.com/log" "go.wit.com/log"
"golang.org/x/text/cases" "golang.org/x/text/cases"
"golang.org/x/text/language" "golang.org/x/text/language"
"github.com/google/uuid"
) )
// this parses the .proto file and handles anything with `autogenpb: ` // this parses the .proto file and handles anything with `autogenpb: `
@ -34,8 +36,10 @@ func (pb *Files) hasPluralMessage(f *File) error {
continue continue
} }
scanner.Scan()
line = scanner.Text() line = scanner.Text()
fields := strings.Fields(line) fields := strings.Fields(line)
// log.Info("GOT LINE", line)
if fields[0] == "string" && fields[1] != "uuid" { if fields[0] == "string" && fields[1] != "uuid" {
f.noUuid() f.noUuid()
return fmt.Errorf("proto file does not have a UUID") return fmt.Errorf("proto file does not have a UUID")
@ -44,8 +48,10 @@ func (pb *Files) hasPluralMessage(f *File) error {
f.Uuid = line f.Uuid = line
log.Info("found UUID:", line) log.Info("found UUID:", line)
scanner.Scan()
line = scanner.Text() line = scanner.Text()
fields = strings.Fields(line) fields = strings.Fields(line)
// log.Info("GOT LINE", line)
if fields[0] == "string" && fields[1] != "version" { if fields[0] == "string" && fields[1] != "version" {
f.noUuid() f.noUuid()
return fmt.Errorf("proto file does not have a version") return fmt.Errorf("proto file does not have a version")
@ -85,6 +91,7 @@ func (pf *File) noPluralMessage() {
func (pf *File) noUuid() { func (pf *File) noUuid() {
base := cases.Title(language.English, cases.NoLower).String(pf.Filebase) base := cases.Title(language.English, cases.NoLower).String(pf.Filebase)
id := uuid.New()
log.Info("") log.Info("")
log.Info("###########################################################################") log.Info("###########################################################################")
@ -92,10 +99,10 @@ func (pf *File) noUuid() {
log.Info("") log.Info("")
log.Info("For autogenpb to work on your file", pf.Filename, ",", base+"s must be exactly:") log.Info("For autogenpb to work on your file", pf.Filename, ",", base+"s must be exactly:")
log.Info("") log.Info("")
log.Info("message Fruits { // `autogenpb:marshal` `autogenpb:mutex`") log.Info("message", base+"s", "{ // `autogenpb:marshal` `autogenpb:mutex`")
log.Info(" string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`") log.Info(" string uuid = 1; // `autogenpb:uuid:" + id.String() + "`")
log.Info(" string version = 2; // `autogenpb:version:v0.0.1`") log.Info(" string version = 2; // `autogenpb:version:v0.0.1`")
log.Info(" repeated Fruit Fruits = 3; // THIS MUST BE ", base, " and then ", base+"s") log.Info(" repeated", base, base+"s", " = 3; // THIS MUST BE ", base, " and then ", base+"s")
log.Info("}") log.Info("}")
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")