()
| 57 | const extensionBrowseURL = "https://geminicli.com/extensions.json" |
| 58 | |
| 59 | func extensionBrowseCommand() *cobra.Command { |
| 60 | return &cobra.Command{ |
| 61 | Use: "browse", |
| 62 | Short: "Browse available Gemini extensions from geminicli.com", |
| 63 | Args: cobra.NoArgs, |
| 64 | RunE: func(cmd *cobra.Command, args []string) error { |
| 65 | out := cmd.OutOrStdout() |
| 66 | url := extensionBrowseURL |
| 67 | if override := os.Getenv("CAM_EXTENSION_BROWSE_URL"); override != "" { |
| 68 | url = override |
| 69 | } |
| 70 | client := &http.Client{Timeout: 15 * time.Second} |
| 71 | resp, err := client.Get(url) |
| 72 | if err != nil { |
| 73 | return fmt.Errorf("browse: %w", err) |
| 74 | } |
| 75 | defer resp.Body.Close() |
| 76 | if resp.StatusCode != http.StatusOK { |
| 77 | return fmt.Errorf("browse: HTTP %d", resp.StatusCode) |
| 78 | } |
| 79 | var payload any |
| 80 | if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil { |
| 81 | return fmt.Errorf("browse: decode: %w", err) |
| 82 | } |
| 83 | items := normalizeExtensions(payload) |
| 84 | if len(items) == 0 { |
| 85 | fmt.Fprintln(out, "No extensions found.") |
| 86 | return nil |
| 87 | } |
| 88 | fmt.Fprintf(out, "Available Gemini Extensions (%d):\n\n", len(items)) |
| 89 | for i, ext := range items { |
| 90 | name, _ := ext["extensionName"].(string) |
| 91 | desc, _ := ext["extensionDescription"].(string) |
| 92 | if desc == "" { |
| 93 | desc, _ = ext["repoDescription"].(string) |
| 94 | } |
| 95 | full, _ := ext["fullName"].(string) |
| 96 | url, _ := ext["url"].(string) |
| 97 | stars := 0 |
| 98 | if s, ok := ext["stars"].(float64); ok { |
| 99 | stars = int(s) |
| 100 | } |
| 101 | fmt.Fprintf(out, "%3d. %s\n %s\n by %s ★ %d\n %s\n\n", |
| 102 | i+1, name, desc, full, stars, url) |
| 103 | } |
| 104 | return nil |
| 105 | }, |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | func normalizeExtensions(payload any) []map[string]any { |
| 110 | switch v := payload.(type) { |
no test coverage detected