MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / setNestedValue

Function setNestedValue

cmd/wsh/cmd/wshcmd-setmeta.go:97–126  ·  view source on GitHub ↗
(meta map[string]any, path []string, value any)

Source from the content-addressed store, hash-verified

95}
96
97func setNestedValue(meta map[string]any, path []string, value any) {
98 // For single key, just set directly
99 if len(path) == 1 {
100 meta[path[0]] = value
101 return
102 }
103
104 // For nested path, traverse or create maps as needed
105 current := meta
106 for i := 0; i < len(path)-1; i++ {
107 key := path[i]
108 // If next level doesn't exist or isn't a map, create new map
109 next, exists := current[key]
110 if !exists {
111 nextMap := make(map[string]any)
112 current[key] = nextMap
113 current = nextMap
114 } else if nextMap, ok := next.(map[string]any); ok {
115 current = nextMap
116 } else {
117 // If existing value isn't a map, replace with new map
118 nextMap = make(map[string]any)
119 current[key] = nextMap
120 current = nextMap
121 }
122 }
123
124 // Set the final value
125 current[path[len(path)-1]] = value
126}
127
128func parseMetaSets(metaSets []string) (map[string]any, error) {
129 meta := make(map[string]any)

Callers 1

parseMetaSetsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected