summaryrefslogtreecommitdiffstats
path: root/cmd/x.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/x.go')
-rw-r--r--cmd/x.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/cmd/x.go b/cmd/x.go
new file mode 100644
index 0000000..b4114b5
--- /dev/null
+++ b/cmd/x.go
@@ -0,0 +1,61 @@
+package cmd
+
+import (
+ "dborg/internal/client"
+ "dborg/internal/config"
+ "encoding/json"
+ "fmt"
+
+ "github.com/spf13/cobra"
+)
+
+var xCmd = &cobra.Command{
+ Use: "x [username]",
+ Short: "Search Twitter/X username history",
+ Long: `Search for Twitter/X username history and previous usernames`,
+ Args: cobra.ExactArgs(1),
+ RunE: runXSearch,
+}
+
+func init() {
+ rootCmd.AddCommand(xCmd)
+}
+
+func runXSearch(cmd *cobra.Command, args []string) error {
+ apiKey, _ := cmd.Flags().GetString("api-key")
+ cfg := config.New().WithAPIKey(apiKey)
+
+ c, err := client.New(cfg)
+ if err != nil {
+ return err
+ }
+
+ response, err := c.SearchTwitterHistory(args[0])
+ if err != nil {
+ return err
+ }
+
+ if response.Error != "" {
+ return fmt.Errorf("API error: %s", response.Error)
+ }
+
+ if len(response.PreviousUsernames) > 0 {
+ output, err := json.MarshalIndent(response.PreviousUsernames, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to format response: %w", err)
+ }
+ fmt.Println(string(output))
+ } else if response.Response != "" {
+ fmt.Println(response.Response)
+ } else if response.Data != nil {
+ output, err := json.MarshalIndent(response.Data, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to format response: %w", err)
+ }
+ fmt.Println(string(output))
+ } else {
+ fmt.Println("No username history found")
+ }
+
+ return nil
+}