MCPcopy
hub / github.com/go-task/task / formatVarValue

Function formatVarValue

internal/summary/summary.go:203–231  ·  view source on GitHub ↗

formatVarValue formats a variable value based on its type. Handles static values, shell commands (sh:), references (ref:), and maps.

(v ast.Var)

Source from the content-addressed store, hash-verified

201// formatVarValue formats a variable value based on its type.
202// Handles static values, shell commands (sh:), references (ref:), and maps.
203func formatVarValue(v ast.Var) string {
204 // Never expose secret variables in the summary, whatever their type
205 if v.Secret {
206 return "*****"
207 }
208
209 // Shell command - check this first before Value
210 // because dynamic vars may have both Sh and an empty Value
211 if v.Sh != nil {
212 return fmt.Sprintf("sh: %s", *v.Sh)
213 }
214
215 // Reference
216 if v.Ref != "" {
217 return fmt.Sprintf("ref: %s", v.Ref)
218 }
219
220 // Static value
221 if v.Value != nil {
222 // Check if it's a map or complex type
223 if m, ok := v.Value.(map[string]any); ok {
224 return formatMap(m, 4)
225 }
226 // Simple string value
227 return fmt.Sprintf(`"%v"`, v.Value)
228 }
229
230 return `""`
231}
232
233// formatMap formats a map value with proper indentation for YAML.
234func formatMap(m map[string]any, indent int) string {

Callers 2

printTaskVarsFunction · 0.85
printTaskEnvFunction · 0.85

Calls 1

formatMapFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…