MCPcopy
hub / github.com/spicetify/cli / arrayType

Function arrayType

src/cmd/config.go:121–184  ·  view source on GitHub ↗
(section *ini.Section, field, value string)

Source from the content-addressed store, hash-verified

119}
120
121func arrayType(section *ini.Section, field, value string) {
122 key, err := section.GetKey(field)
123 if err != nil {
124 utils.Fatal(err)
125 }
126
127 if strings.TrimSpace(value) == "" {
128 key.SetValue("")
129 changeSuccess(field, "")
130 return
131 }
132
133 allExts := make(map[string]bool)
134 for _, v := range key.Strings("|") {
135 allExts[v] = true
136 }
137
138 values := strings.Split(value, "|")
139 duplicates := []string{}
140 inputValues := make(map[string]bool)
141 modifiedValues := 0
142
143 for _, value := range values {
144 isSubstract := strings.HasSuffix(value, "-")
145 if isSubstract {
146 value = value[:len(value)-1]
147 }
148
149 if isSubstract {
150 if _, found := allExts[value]; !found {
151 unchangeWarning(field, fmt.Sprintf("%s is not on the list.", value))
152 return
153 }
154
155 modifiedValues++
156 delete(allExts, value)
157 } else {
158 if _, found := allExts[value]; found && !inputValues[value] {
159 duplicates = append(duplicates, value)
160 } else if _, found := allExts[value]; !found {
161 allExts[value] = true
162 modifiedValues++
163 }
164
165 inputValues[value] = true
166 }
167 }
168
169 if len(duplicates) > 0 {
170 unchangeWarning(field, fmt.Sprintf("%s %s already in the list.", strings.Join(duplicates, ", "), pluralize(len(duplicates), "is", "are")))
171 }
172
173 if modifiedValues == 0 {
174 return
175 }
176
177 newList := make([]string, 0, len(allExts))
178 for k := range allExts {

Callers 1

EditConfigFunction · 0.85

Calls 4

FatalFunction · 0.92
changeSuccessFunction · 0.85
unchangeWarningFunction · 0.85
pluralizeFunction · 0.85

Tested by

no test coverage detected