Search performs a fan-out search across all registries.
(ctx context.Context, query string)
| 172 | |
| 173 | // Search performs a fan-out search across all registries. |
| 174 | func (sh *SkillHandler) Search(ctx context.Context, query string) { |
| 175 | fmt.Printf("\n %s %s...\n", |
| 176 | i18n.T("skill.search.searching"), |
| 177 | colorize(fmt.Sprintf("%q", query), ColorCyan)) |
| 178 | |
| 179 | ctx, cancel := context.WithTimeout(ctx, 30*time.Second) |
| 180 | defer cancel() |
| 181 | |
| 182 | merged, results := sh.registryMgr.SearchAll(ctx, query) |
| 183 | |
| 184 | // Show concise errors from individual registries (only first-time errors, auto-disable handles the rest) |
| 185 | hasErrors := false |
| 186 | for _, r := range results { |
| 187 | if r.Error != nil { |
| 188 | if !hasErrors { |
| 189 | fmt.Println() |
| 190 | hasErrors = true |
| 191 | } |
| 192 | fmt.Printf(" %s %s: %s\n", |
| 193 | colorize("!", ColorYellow), |
| 194 | r.RegistryName, |
| 195 | colorize(shortenRegistryError(r.Error), ColorGray)) |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if len(merged) == 0 { |
| 200 | fmt.Printf("\n %s\n\n", colorize(i18n.T("skill.search.no_results"), ColorYellow)) |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | fmt.Printf("\n %s:\n\n", i18n.T("skill.search.results", len(merged))) |
| 205 | |
| 206 | // Compute max name length for alignment |
| 207 | maxNameLen := 0 |
| 208 | for _, skill := range merged { |
| 209 | if len(skill.Name) > maxNameLen { |
| 210 | maxNameLen = len(skill.Name) |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | for i, skill := range merged { |
| 215 | // Padded name (pad raw string, then colorize) |
| 216 | paddedName := fmt.Sprintf("%-*s", maxNameLen, skill.Name) |
| 217 | |
| 218 | // Version |
| 219 | versionStr := "" |
| 220 | if skill.Version != "" { |
| 221 | versionStr = fmt.Sprintf("v%s", skill.Version) |
| 222 | } |
| 223 | |
| 224 | // Registry tag |
| 225 | regTag := fmt.Sprintf("[%s]", skill.RegistryName) |
| 226 | |
| 227 | // Install count (formatted for skills.sh) |
| 228 | installStr := "" |
| 229 | if skill.Downloads > 0 { |
| 230 | installStr = registry.FormatInstallCount(skill.Downloads) |
| 231 | } |
no test coverage detected