From 4e2ab5731832bae966cf4246e335dae0424bc271 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Sat, 8 Feb 2025 00:45:39 +0100
Subject: [PATCH] feat: add verbose flag and fix text infos

---
 source/command.go          |  3 ++-
 source/main.go             |  9 +++++++++
 source/template/prepare.go | 10 ++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/source/command.go b/source/command.go
index 20bd3ea..bd88abe 100644
--- a/source/command.go
+++ b/source/command.go
@@ -18,7 +18,8 @@ import (
 )
 
 type Definition struct {
-	Help struct {
+	Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"`
+	Help    struct {
 	} `command:"help" call:"PrintHelp" description:"Prints this help message"`
 	Template struct {
 		Prepare struct {
diff --git a/source/main.go b/source/main.go
index c9e634b..fa31463 100644
--- a/source/main.go
+++ b/source/main.go
@@ -2,6 +2,7 @@ package main
 
 import (
 	"fmt"
+	"github.com/charmbracelet/log"
 	xflags "gitlab.schukai.com/oss/libraries/go/application/xflags.git"
 
 	"os"
@@ -14,8 +15,16 @@ func main() {
 	definition := Definition{}
 	definition.Template.Prepare.DataFile = "data.yaml"
 
+	logger := log.Default()
+	logger.SetLevel(log.ErrorLevel)
+
 	settings = xflags.New(os.Args[0], definition)
 	settings.Parse(os.Args[1:])
+
+	if settings.GetValues().Verbose {
+		logger.SetLevel(log.DebugLevel)
+	}
+
 	settings.Execute()
 
 	if settings.HasErrors() {
diff --git a/source/template/prepare.go b/source/template/prepare.go
index de3624c..c50fa1f 100644
--- a/source/template/prepare.go
+++ b/source/template/prepare.go
@@ -413,6 +413,7 @@ func removeDuplicateWhitespaces(str string) string {
 
 func handleTextNode(n *html.Node, storage *types.PageData) {
 	content := strings.TrimSpace(n.Data)
+
 	if content == "" {
 		return
 	}
@@ -425,6 +426,15 @@ func handleTextNode(n *html.Node, storage *types.PageData) {
 
 			// if span and has constants.DataBobReferenceAttributeKey, ignore
 			if n.Parent.Data == "span" && util.HasAttribute(n.Parent.Attr, constants.DataBobReferenceAttributeKey) {
+
+				id := util.GetAttribute(n.Parent.Attr, constants.DataBobReferenceAttributeKey)
+
+				log.Info("Added text: " + id + " (" + logContent + ") to storage")
+				storage.Text = append(storage.Text, types.Text{
+					Id:   id,
+					Text: content,
+				})
+
 				return
 			}
 
-- 
GitLab