MCPcopy
hub / github.com/1Password/for-open-source / stringSection

Method stringSection

script/application.go:224–254  ·  view source on GitHub ↗
(sectionName string, required bool, callbacks ...ValidatorCallback)

Source from the content-addressed store, hash-verified

222}
223
224func (a *Application) stringSection(sectionName string, required bool, callbacks ...ValidatorCallback) string {
225 value, exists := a.sections[sectionName]
226 _, value, _ = ParseInput(value)
227
228 // If the section is required, apply the presence validator if the entry
229 // exists, early fail validation if it doesn't exist. If the section is
230 // not required and there is no content to work with, don't try to run
231 // additional validations.
232 if required {
233 if exists {
234 callbacks = append([]ValidatorCallback{IsPresent}, callbacks...)
235 } else {
236 a.validator.AddError(sectionName, value, "was not completed for application")
237 return value
238 }
239 } else if !exists || value == "" {
240 return value
241 }
242
243 for _, callback := range callbacks {
244 pass, newValue, message := callback(value)
245 value = newValue
246
247 if !pass {
248 a.validator.AddError(sectionName, value, message)
249 break
250 }
251 }
252
253 return value
254}
255
256func (a *Application) intSection(sectionName string, required bool, callbacks ...ValidatorCallback) int {
257 value := a.stringSection(sectionName, required, callbacks...)

Callers 3

ParseMethod · 0.95
intSectionMethod · 0.95
boolSectionMethod · 0.95

Calls 2

ParseInputFunction · 0.85
AddErrorMethod · 0.80

Tested by

no test coverage detected