summaryrefslogtreecommitdiffstats
path: root/cmd/reddit.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/reddit.go')
-rw-r--r--cmd/reddit.go42
1 files changed, 6 insertions, 36 deletions
diff --git a/cmd/reddit.go b/cmd/reddit.go
index 2341322..1096a23 100644
--- a/cmd/reddit.go
+++ b/cmd/reddit.go
@@ -1,12 +1,12 @@
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"
"github.com/spf13/cobra"
)
@@ -103,13 +103,7 @@ func runRedditSubredditPosts(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- output, err := json.MarshalIndent(response, "", " ")
- if err != nil {
- return fmt.Errorf("failed to format response: %w", err)
- }
-
- fmt.Println(string(output))
- return nil
+ return utils.PrintJSON(response)
}
func runRedditSubredditComments(cmd *cobra.Command, args []string) error {
@@ -134,13 +128,7 @@ func runRedditSubredditComments(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- output, err := json.MarshalIndent(response, "", " ")
- if err != nil {
- return fmt.Errorf("failed to format response: %w", err)
- }
-
- fmt.Println(string(output))
- return nil
+ return utils.PrintJSON(response)
}
func runRedditUserPosts(cmd *cobra.Command, args []string) error {
@@ -165,13 +153,7 @@ func runRedditUserPosts(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- output, err := json.MarshalIndent(response, "", " ")
- if err != nil {
- return fmt.Errorf("failed to format response: %w", err)
- }
-
- fmt.Println(string(output))
- return nil
+ return utils.PrintJSON(response)
}
func runRedditUserComments(cmd *cobra.Command, args []string) error {
@@ -196,13 +178,7 @@ func runRedditUserComments(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- output, err := json.MarshalIndent(response, "", " ")
- if err != nil {
- return fmt.Errorf("failed to format response: %w", err)
- }
-
- fmt.Println(string(output))
- return nil
+ return utils.PrintJSON(response)
}
func runRedditUserAbout(cmd *cobra.Command, args []string) error {
@@ -227,11 +203,5 @@ func runRedditUserAbout(cmd *cobra.Command, args []string) error {
return fmt.Errorf("API error: %s", response.Error)
}
- output, err := json.MarshalIndent(response, "", " ")
- if err != nil {
- return fmt.Errorf("failed to format response: %w", err)
- }
-
- fmt.Println(string(output))
- return nil
+ return utils.PrintJSON(response)
}