From f7fcfa623e670dc533bb378912829c73a3593e63 Mon Sep 17 00:00:00 2001 From: s Date: Mon, 3 Nov 2025 21:17:12 -0500 Subject: hi --- cmd/x.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 cmd/x.go (limited to 'cmd/x.go') 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 +} -- cgit v1.2.3