formatVarValue formats a variable value based on its type. Handles static values, shell commands (sh:), references (ref:), and maps.
(v ast.Var)
| 201 | // formatVarValue formats a variable value based on its type. |
| 202 | // Handles static values, shell commands (sh:), references (ref:), and maps. |
| 203 | func 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. |
| 234 | func formatMap(m map[string]any, indent int) string { |
no test coverage detected
searching dependent graphs…