diff options
| author | Jeff Carr <[email protected]> | 2025-10-12 17:50:00 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-13 03:28:10 -0500 |
| commit | 4cefe0bf52f9d60d25858ebb51b870433004a4a6 (patch) | |
| tree | f859c5b64c25abe0e4413aeb44e120a7c9ae1901 /find.go | |
| parent | 29bb90b293a8bda889ff30bb56d05ce47af4a9bf (diff) | |
cleaning up stuff. finally making progress
Diffstat (limited to 'find.go')
| -rw-r--r-- | find.go | 92 |
1 files changed, 92 insertions, 0 deletions
@@ -1,8 +1,14 @@ package main import ( + "fmt" "os" "path/filepath" + + "go.wit.com/lib/config" + "go.wit.com/log" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" ) func FindFiles(lookhere string) ([]string, error) { @@ -21,3 +27,89 @@ func FindFiles(lookhere string) ([]string, error) { return allfiles, err } + +// this is terrible and I regret making this +func printDebInfoStrings(pb proto.Message, fallback bool) (string, error) { + var verbose bool + var controlfile string + // 1. Get the reflection interface for the top-level message. + msg := pb.ProtoReflect() + descriptor := msg.Descriptor() + + // 2. Find the FieldDescriptor for the nested "debInfo" message. + // Note: Protobuf field names like "deb_info" are often canonicalized + // to "debInfo" in Go code, but reflection should use the name from the .proto file. + // We'll check for both common variations for robustness. + + debInfoFieldDesc := descriptor.Fields().ByName("debInfo") + if debInfoFieldDesc == nil { + debInfoFieldDesc = descriptor.Fields().ByName("deb_info") + } + + if debInfoFieldDesc == nil { + return controlfile, fmt.Errorf("field 'debInfo' or 'deb_info' not found in message %s", descriptor.FullName()) + } + + // 3. Get the actual nested message object from the parent. + debInfoValue := msg.Get(debInfoFieldDesc) + debInfoMsg := debInfoValue.Message() + + // 4. Check if the nested message is valid and has been set. + if !debInfoMsg.IsValid() { + fmt.Printf("--- Field '%s' in [%s] is not set. --- \n", debInfoFieldDesc.Name(), descriptor.FullName()) + return controlfile, nil // Not an error, just nothing to print. + } + + // 5. Now, iterate over the fields of the nested debInfo message. + debInfoDescriptor := debInfoMsg.Descriptor() + fields := debInfoDescriptor.Fields() + + if verbose { + fmt.Printf("--- Listing String Fields in '%s' --- \n", debInfoFieldDesc.Name()) + } + foundStrings := false + for i := 0; i < fields.Len(); i++ { + fieldDesc := fields.Get(i) + + // 6. Check if the field's kind is a string. + if fieldDesc.Kind() == protoreflect.StringKind { + var value string + var fieldName protoreflect.Name + // Get the value from the debInfo message object. + value = debInfoMsg.Get(fieldDesc).String() + fieldName = fieldDesc.Name() + if value == "" { + if verbose { + log.Info(string(fieldName), "is blank") + } + newval, err := config.GetString(pb, string(fieldName)) + if err != nil { + if verbose { + log.Info("GetString() failed", newval, err) + } + continue + } else { + if verbose { + log.Info("GetString() worked:", newval) + } + value = newval + } + } + if value == "" { + // still blank after backup lookup + continue + } + + // Print the result. + fmt.Printf("%s: \"%s\"\n", string(fieldName), value) + controlfile += fmt.Sprintf("%s: %s\n", string(fieldName), value) + foundStrings = true + } + } + + if !foundStrings { + fmt.Println(" (No string fields found)") + } + + return controlfile, nil +} |
