diff options
| author | s <[email protected]> | 2025-11-03 21:17:12 -0500 |
|---|---|---|
| committer | s <[email protected]> | 2025-11-03 21:17:12 -0500 |
| commit | f7fcfa623e670dc533bb378912829c73a3593e63 (patch) | |
| tree | 910119ff7293b407affa9ff34706d627d77a3a04 /cmd/x.go | |
| download | dborg-f7fcfa623e670dc533bb378912829c73a3593e63.tar.gz dborg-f7fcfa623e670dc533bb378912829c73a3593e63.zip | |
hi
Diffstat (limited to 'cmd/x.go')
| -rw-r--r-- | cmd/x.go | 61 |
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 +} |
