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

Function formatQualifiers

pkg/search/query.go:298–338  ·  view source on GitHub ↗

formatQualifiers renders qualifiers into a plain query. The formatter is a custom formatting function that can be used to modify the output of each qualifier. If the formatter returns (nil, false) the default formatting will be applied.

(qs Qualifiers, formatter func(qualifier string, vs []string) (s []string, applicable bool))

Source from the content-addressed store, hash-verified

296// output of each qualifier. If the formatter returns (nil, false) the default
297// formatting will be applied.
298func formatQualifiers(qs Qualifiers, formatter func(qualifier string, vs []string) (s []string, applicable bool)) []string {
299 type entry struct {
300 key string
301 values []string
302 }
303
304 var all []entry
305 for k, vs := range qs.Map() {
306 if len(vs) == 0 {
307 continue
308 }
309
310 e := entry{key: k}
311
312 if formatter != nil {
313 if s, applicable := formatter(k, vs); applicable {
314 e.values = s
315 all = append(all, e)
316 continue
317 }
318 }
319
320 for _, v := range vs {
321 e.values = append(e.values, fmt.Sprintf("%s:%s", k, quote(v)))
322 }
323 if len(e.values) > 1 {
324 slices.Sort(e.values)
325 }
326 all = append(all, e)
327 }
328
329 slices.SortFunc(all, func(a, b entry) int {
330 return strings.Compare(a.key, b.key)
331 })
332
333 result := make([]string, 0, len(all))
334 for _, e := range all {
335 result = append(result, e.values...)
336 }
337 return result
338}
339
340func formatKeywords(ks []string) []string {
341 result := make([]string, len(ks))

Callers 2

StandardSearchStringMethod · 0.85

Calls 2

quoteFunction · 0.85
MapMethod · 0.80

Tested by

no test coverage detected