summaryrefslogtreecommitdiffstats
path: root/cmd/x.go
diff options
context:
space:
mode:
authors <[email protected]>2025-11-13 22:25:02 -0500
committers <[email protected]>2025-11-13 22:25:02 -0500
commit07662d9403eb85b39e1ffcf91014bbf36efd1c5a (patch)
tree1181435223899bae039a947c5fc4fdeec085f91b /cmd/x.go
parent239936e87183a10a33ce593709eb16c92a04af98 (diff)
downloaddborg-07662d9403eb85b39e1ffcf91014bbf36efd1c5a.tar.gz
dborg-07662d9403eb85b39e1ffcf91014bbf36efd1c5a.zip
refactor: break down large osint.go file into separate command modules and add helper functionsv1.0.1
Diffstat (limited to 'cmd/x.go')
-rw-r--r--cmd/x.go44
1 files changed, 15 insertions, 29 deletions
diff --git a/cmd/x.go b/cmd/x.go
index ba18aa8..c5c18e4 100644
--- a/cmd/x.go
+++ b/cmd/x.go
@@ -2,12 +2,9 @@ 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/formatter"
"git.db.org.ai/dborg/internal/models"
-
"github.com/spf13/cobra"
)
@@ -79,9 +76,7 @@ func init() {
}
func runXHistorySearch(cmd *cobra.Command, args []string) error {
- cfg := config.New()
-
- c, err := client.New(cfg)
+ c, err := newClient()
if err != nil {
return err
}
@@ -91,23 +86,20 @@ func runXHistorySearch(cmd *cobra.Command, args []string) error {
return err
}
- if response.Error != "" {
- return fmt.Errorf("API error: %s", response.Error)
+ if err := checkError(response.Error); err != nil {
+ return err
}
output, err := formatter.FormatXHistory(response, IsJSONOutput())
if err != nil {
return err
}
-
- fmt.Print(output)
+ printOutput(output)
return nil
}
func runXTweetsSearch(cmd *cobra.Command, args []string) error {
- cfg := config.New()
-
- c, err := client.NewUnauthenticated(cfg)
+ c, err := newClient()
if err != nil {
return err
}
@@ -123,7 +115,7 @@ func runXTweetsSearch(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Print(output)
+ printOutput(output)
return nil
})
@@ -135,9 +127,7 @@ func runXTweetsSearch(cmd *cobra.Command, args []string) error {
}
func runXFirstFollowers(cmd *cobra.Command, args []string) error {
- cfg := config.New()
-
- c, err := client.New(cfg)
+ c, err := newClient()
if err != nil {
return err
}
@@ -152,14 +142,12 @@ func runXFirstFollowers(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Print(output)
+ printOutput(output)
return nil
}
func runXNotableFollowers(cmd *cobra.Command, args []string) error {
- cfg := config.New()
-
- c, err := client.New(cfg)
+ c, err := newClient()
if err != nil {
return err
}
@@ -174,15 +162,14 @@ func runXNotableFollowers(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Print(output)
+ printOutput(output)
return nil
}
func runXReplies(cmd *cobra.Command, args []string) error {
limit, _ := cmd.Flags().GetInt("limit")
- cfg := config.New()
- c, err := client.New(cfg)
+ c, err := newClient()
if err != nil {
return err
}
@@ -198,7 +185,7 @@ func runXReplies(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Print(output)
+ printOutput(output)
return nil
})
@@ -211,9 +198,8 @@ func runXReplies(cmd *cobra.Command, args []string) error {
func runXSearch(cmd *cobra.Command, args []string) error {
limit, _ := cmd.Flags().GetInt("limit")
- cfg := config.New()
- c, err := client.New(cfg)
+ c, err := newClient()
if err != nil {
return err
}
@@ -229,7 +215,7 @@ func runXSearch(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Print(output)
+ printOutput(output)
return nil
})