From 7d63867f365163f149db5d768c71f518f9eaf711 Mon Sep 17 00:00:00 2001 From: s Date: Fri, 7 Nov 2025 11:50:47 -0500 Subject: refactor: extract json output formatting to utils.PrintJSON and add colorized json output with new dns tld command --- cmd/skiptrace.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'cmd/skiptrace.go') diff --git a/cmd/skiptrace.go b/cmd/skiptrace.go index 6b0ad0b..a9ab862 100644 --- a/cmd/skiptrace.go +++ b/cmd/skiptrace.go @@ -1,11 +1,11 @@ package cmd import ( - "encoding/json" "fmt" "git.db.org.ai/dborg/internal/client" "git.db.org.ai/dborg/internal/config" "git.db.org.ai/dborg/internal/models" + "git.db.org.ai/dborg/internal/utils" "strconv" "github.com/spf13/cobra" @@ -92,11 +92,7 @@ func runSkiptracePeople(cmd *cobra.Command, args []string) error { } if response.Data != nil && len(response.Data) > 0 { - output, err := json.MarshalIndent(response.Data, "", " ") - if err != nil { - return fmt.Errorf("failed to format response: %w", err) - } - fmt.Println(string(output)) + return utils.PrintJSON(response.Data) } return nil @@ -124,11 +120,9 @@ func runSkiptraceReport(cmd *cobra.Command, args []string) error { } if response.Data != nil && len(response.Data) > 0 { - output, err := json.MarshalIndent(response.Data, "", " ") - if err != nil { - return fmt.Errorf("failed to format response: %w", err) + if err := utils.PrintJSON(response.Data); err != nil { + return err } - fmt.Println(string(output)) } if response.Message != "" { @@ -154,11 +148,9 @@ func runSkiptracePhone(cmd *cobra.Command, args []string) error { } if response.Data != nil && len(response.Data) > 0 { - output, err := json.MarshalIndent(response.Data, "", " ") - if err != nil { - return fmt.Errorf("failed to format response: %w", err) + if err := utils.PrintJSON(response.Data); err != nil { + return err } - fmt.Println(string(output)) } if response.Message != "" { @@ -184,11 +176,9 @@ func runSkiptraceEmail(cmd *cobra.Command, args []string) error { } if response.Data != nil && len(response.Data) > 0 { - output, err := json.MarshalIndent(response.Data, "", " ") - if err != nil { - return fmt.Errorf("failed to format response: %w", err) + if err := utils.PrintJSON(response.Data); err != nil { + return err } - fmt.Println(string(output)) } if response.Message != "" { -- cgit v1.2.3