summaryrefslogtreecommitdiffstats
path: root/internal/utils/output.go
diff options
context:
space:
mode:
authors <[email protected]>2025-11-03 21:17:12 -0500
committers <[email protected]>2025-11-03 21:17:12 -0500
commitf7fcfa623e670dc533bb378912829c73a3593e63 (patch)
tree910119ff7293b407affa9ff34706d627d77a3a04 /internal/utils/output.go
downloaddborg-f7fcfa623e670dc533bb378912829c73a3593e63.tar.gz
dborg-f7fcfa623e670dc533bb378912829c73a3593e63.zip
hi
Diffstat (limited to 'internal/utils/output.go')
-rw-r--r--internal/utils/output.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/utils/output.go b/internal/utils/output.go
new file mode 100644
index 0000000..3f2347c
--- /dev/null
+++ b/internal/utils/output.go
@@ -0,0 +1,39 @@
+package utils
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "text/tabwriter"
+)
+
+func PrintJSON(data any) error {
+ output, err := json.MarshalIndent(data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to format JSON: %w", err)
+ }
+ fmt.Println(string(output))
+ return nil
+}
+
+func PrintTable(headers []string, rows [][]string) {
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
+ defer w.Flush()
+
+ for _, h := range headers {
+ fmt.Fprintf(w, "%s\t", h)
+ }
+ fmt.Fprintln(w)
+
+ for _, row := range rows {
+ for _, col := range row {
+ fmt.Fprintf(w, "%s\t", col)
+ }
+ fmt.Fprintln(w)
+ }
+}
+
+func PrintError(err error) {
+ fmt.Fprintf(os.Stderr, "Error: %v\n", err)
+ os.Exit(1)
+}