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

Method Map

pkg/search/query.go:249–284  ·  view source on GitHub ↗

Map turns the qualifiers into a slice-keyed map ready for query formatting. Multiple struct fields can share the same key when tagged with `qualifier:" "`; in that case their values are concatenated under the shared key.

()

Source from the content-addressed store, hash-verified

247// tagged with `qualifier:"<name>"`; in that case their values are
248// concatenated under the shared key.
249func (q Qualifiers) Map() map[string][]string {
250 m := map[string][]string{}
251 v := reflect.ValueOf(q)
252 t := reflect.TypeFor[Qualifiers]()
253 for i := 0; i < v.NumField(); i++ {
254 field := t.Field(i)
255 key := field.Tag.Get("qualifier")
256 if key == "" {
257 key = camelToKebab(field.Name)
258 }
259 value := v.Field(i)
260 switch value.Kind() {
261 case reflect.Pointer:
262 if value.IsNil() {
263 continue
264 }
265 m[key] = append(m[key], fmt.Sprintf("%v", reflect.Indirect(value)))
266 case reflect.Slice:
267 if value.IsNil() {
268 continue
269 }
270 for j := 0; j < value.Len(); j++ {
271 if value.Index(j).IsZero() {
272 continue
273 }
274 m[key] = append(m[key], fmt.Sprintf("%v", value.Index(j)))
275 }
276 default:
277 if value.IsZero() {
278 continue
279 }
280 m[key] = append(m[key], fmt.Sprintf("%v", value))
281 }
282 }
283 return m
284}
285
286func quote(s string) string {
287 if strings.ContainsAny(s, " \"\t\r\n") {

Callers 8

formatQualifiersFunction · 0.80
TestQualifiersMapFunction · 0.80
humanizeFunction · 0.80
ExampleMapFunction · 0.80
TestMapFunction · 0.80
stripControlFunction · 0.80
GetOrDefaultMethod · 0.80
shortenQueryFunction · 0.80

Calls 3

camelToKebabFunction · 0.85
GetMethod · 0.65
LenMethod · 0.65

Tested by 3

TestQualifiersMapFunction · 0.64
ExampleMapFunction · 0.64
TestMapFunction · 0.64