summaryrefslogtreecommitdiff
path: root/find.go
diff options
context:
space:
mode:
Diffstat (limited to 'find.go')
-rw-r--r--find.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/find.go b/find.go
index 31e581c..58260bc 100644
--- a/find.go
+++ b/find.go
@@ -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
+}