MCPcopy Create free account
hub / github.com/github/gh-aw / coerceStringOrArrayField

Function coerceStringOrArrayField

pkg/workflow/parse_helpers.go:28–43  ·  view source on GitHub ↗

coerceStringOrArrayField converts configData[key] from a string to []string{value} so YAML unmarshaling into []string fields succeeds for single-value shorthand. When key is missing, nil, or already a non-string type, this function is a no-op. The debugLog parameter is optional; pass nil to suppres

(configData map[string]any, key string, debugLog *logger.Logger)

Source from the content-addressed store, hash-verified

26// When key is missing, nil, or already a non-string type, this function is a no-op.
27// The debugLog parameter is optional; pass nil to suppress debug output.
28func coerceStringOrArrayField(configData map[string]any, key string, debugLog *logger.Logger) {
29 if configData == nil {
30 return
31 }
32
33 if value, exists := configData[key]; exists {
34 if stringValue, ok := value.(string); ok {
35 configData[key] = []string{stringValue}
36 if debugLog != nil {
37 debugLog.Printf("Converted single %s string to array before unmarshaling", key)
38 } else {
39 parseHelpersLog.Printf("Coerced %s scalar to single-element array (no caller log provided)", key)
40 }
41 }
42 }
43}
44
45// coerceStringOrArrayFields applies coerceStringOrArrayField to multiple keys.
46func coerceStringOrArrayFields(configData map[string]any, keys []string, debugLog *logger.Logger) {

Callers 1

Calls 1

PrintfMethod · 0.45

Tested by

no test coverage detected