summaryrefslogtreecommitdiffstats
path: root/internal/formatter/shortlinks.go
diff options
context:
space:
mode:
authors <[email protected]>2025-11-13 14:43:15 -0500
committers <[email protected]>2025-11-13 14:43:15 -0500
commit344a6f6415c3c1b593677adec3b8844e0839971b (patch)
treeb05291ecdf21917b27e9e234eeb997c2706966d5 /internal/formatter/shortlinks.go
parenta5fc01a03753c9a18ddeaf13610dd99b4b311b80 (diff)
downloaddborg-344a6f6415c3c1b593677adec3b8844e0839971b.tar.gz
dborg-344a6f6415c3c1b593677adec3b8844e0839971b.zip
created pretty printing for all commandsv1.0.0
Diffstat (limited to 'internal/formatter/shortlinks.go')
-rw-r--r--internal/formatter/shortlinks.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/internal/formatter/shortlinks.go b/internal/formatter/shortlinks.go
new file mode 100644
index 0000000..d6073cb
--- /dev/null
+++ b/internal/formatter/shortlinks.go
@@ -0,0 +1,80 @@
+package formatter
+
+import (
+ "fmt"
+ "strings"
+
+ "git.db.org.ai/dborg/internal/models"
+ "git.db.org.ai/dborg/internal/utils"
+)
+
+func FormatShortlinksResults(response *models.ShortlinksSearchResponse, asJSON bool) error {
+ if asJSON {
+ return utils.PrintJSON(response)
+ }
+
+ if response.Results == nil {
+ PrintWarning("No results found")
+ return nil
+ }
+
+ resultsMap, ok := response.Results.(map[string]interface{})
+ if !ok {
+ return utils.PrintJSON(response)
+ }
+
+ hits, ok := resultsMap["hits"].([]interface{})
+ if !ok || len(hits) == 0 {
+ PrintWarning("No results found")
+ return nil
+ }
+
+ numHits, _ := resultsMap["num_hits"].(float64)
+ elapsed, _ := resultsMap["elapsed_time_micros"].(float64)
+
+ fmt.Printf("%s %s %s\n",
+ Cyan("Found"),
+ Bold(Yellow(fmt.Sprintf("%d", int(numHits)))),
+ Cyan(fmt.Sprintf("credentials (%.2fms)", elapsed/1000)))
+ fmt.Println()
+
+ for i, hit := range hits {
+ hitMap, ok := hit.(map[string]interface{})
+ if !ok {
+ continue
+ }
+
+ if i > 0 {
+ fmt.Println(Dim(strings.Repeat("─", 80)))
+ }
+
+ username, _ := hitMap["username"].(string)
+ password, _ := hitMap["password"].(string)
+ url, _ := hitMap["url"].(string)
+ filename, _ := hitMap["filename"].(string)
+
+ fmt.Printf("%s %s\n", Bold(Green("●")), Bold(username))
+
+ if password != "" {
+ fmt.Printf(" %s %s\n", Dim("Password:"), Yellow(password))
+ }
+
+ if url != "" {
+ fmt.Printf(" %s %s\n", Dim("URL:"), Blue(url))
+ }
+
+ if filename != "" {
+ fmt.Printf(" %s %s\n", Dim("Source:"), Magenta(filename))
+ }
+
+ fmt.Println()
+ }
+
+ if response.Credits.Unlimited {
+ fmt.Printf("%s: %s\n", Dim("Credits"), Green("Unlimited"))
+ } else {
+ fmt.Printf("%s: %s\n", Dim("Credits Remaining"), FormatCredits(int64(response.Credits.Remaining)))
+ }
+
+ return nil
+}