MCPcopy Index your code
hub / github.com/cli/cli / addParamsSlice

Function addParamsSlice

pkg/cmd/api/fields.go:135–158  ·  view source on GitHub ↗
(m map[string]interface{}, prevkey, newkey string)

Source from the content-addressed store, hash-verified

133}
134
135func addParamsSlice(m map[string]interface{}, prevkey, newkey string) (map[string]interface{}, error) {
136 if v, exists := m[prevkey]; exists {
137 if existSlice, ok := v.([]interface{}); ok {
138 if len(existSlice) > 0 {
139 lastItem := existSlice[len(existSlice)-1]
140 if lastMap, ok := lastItem.(map[string]interface{}); ok {
141 if _, keyExists := lastMap[newkey]; !keyExists {
142 return lastMap, nil
143 } else if reflect.TypeOf(lastMap[newkey]).Kind() == reflect.Slice {
144 return lastMap, nil
145 }
146 }
147 }
148 newMap := make(map[string]interface{})
149 m[prevkey] = append(existSlice, newMap)
150 return newMap, nil
151 } else {
152 return nil, fmt.Errorf("expected array type under %q, got %T", prevkey, v)
153 }
154 }
155 newMap := make(map[string]interface{})
156 m[prevkey] = []interface{}{newMap}
157 return newMap, nil
158}
159
160func magicFieldValue(v string, opts *ApiOptions) (interface{}, error) {
161 if strings.HasPrefix(v, "@") {

Callers 1

parseFieldsFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected