MCPcopy
hub / github.com/cli/cli / Map

Method Map

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

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

Callers 7

formatQualifiersFunction · 0.80
TestQualifiersMapFunction · 0.80
humanizeFunction · 0.80
ExampleMapFunction · 0.80
TestMapFunction · 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