MCPcopy Create free account
hub / github.com/cli/cli / skillSearchFunc

Function skillSearchFunc

pkg/cmd/skills/install/install.go:844–882  ·  view source on GitHub ↗

skillSearchFunc returns a search function for MultiSelectWithSearch that filters skills by case-insensitive substring match on name and description.

(skills []discovery.Skill, labelWidth int)

Source from the content-addressed store, hash-verified

842// skillSearchFunc returns a search function for MultiSelectWithSearch that
843// filters skills by case-insensitive substring match on name and description.
844func skillSearchFunc(skills []discovery.Skill, labelWidth int) func(string) prompter.MultiSelectSearchResult {
845 return func(query string) prompter.MultiSelectSearchResult {
846 var matched []discovery.Skill
847 if query == "" {
848 matched = skills
849 } else {
850 q := strings.ToLower(query)
851 for _, s := range skills {
852 if strings.Contains(strings.ToLower(s.DisplayName()), q) ||
853 strings.Contains(strings.ToLower(s.Description), q) {
854 matched = append(matched, s)
855 }
856 }
857 }
858
859 more := 0
860 if len(matched) > maxSearchResults {
861 more = len(matched) - maxSearchResults
862 matched = matched[:maxSearchResults]
863 }
864
865 keys := make([]string, len(matched))
866 labels := make([]string, len(matched))
867 for i, s := range matched {
868 keys[i] = s.DisplayName()
869 label := s.DisplayName()
870 if s.Description != "" {
871 label = fmt.Sprintf("%s - %s", label, text.RemoveExcessiveWhitespace(s.Description))
872 }
873 labels[i] = text.Truncate(labelWidth, label)
874 }
875
876 return prompter.MultiSelectSearchResult{
877 Keys: keys,
878 Labels: labels,
879 MoreResults: more,
880 }
881 }
882}
883
884// matchSelectedSkills maps display names back to skill structs.
885func matchSelectedSkills(skills []discovery.Skill, selected []string) ([]discovery.Skill, error) {

Calls 4

TruncateFunction · 0.92
ContainsMethod · 0.80
DisplayNameMethod · 0.65