MCPcopy
hub / github.com/cli/cli / formatQualifiers

Function formatQualifiers

pkg/search/query.go:291–331  ·  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

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

Callers 2

StandardSearchStringMethod · 0.85

Calls 2

quoteFunction · 0.85
MapMethod · 0.80

Tested by

no test coverage detected