package cmd import ( "encoding/json" "fmt" "git.db.org.ai/dborg/internal/client" "git.db.org.ai/dborg/internal/config" "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 }