hasExitedBlock checks if we've left a YAML block (found a line with same or less indentation that's a key)
(line, blockIndent string)
| 67 | |
| 68 | // hasExitedBlock checks if we've left a YAML block (found a line with same or less indentation that's a key) |
| 69 | func hasExitedBlock(line, blockIndent string) bool { |
| 70 | trimmed := strings.TrimSpace(line) |
| 71 | if trimmed == "" { |
| 72 | return false |
| 73 | } |
| 74 | |
| 75 | currentIndent := getIndentation(line) |
| 76 | |
| 77 | // If it's a comment, check indentation to see if we've exited |
| 78 | if strings.HasPrefix(trimmed, "#") { |
| 79 | return len(currentIndent) <= len(blockIndent) |
| 80 | } |
| 81 | |
| 82 | // For regular lines, we've exited if indentation is same or less and it contains a colon |
| 83 | return len(currentIndent) <= len(blockIndent) && strings.Contains(line, ":") |
| 84 | } |
| 85 | |
| 86 | // findAndReplaceInLine replaces oldKey with newKey in a YAML line, preserving value and comments |
| 87 | func findAndReplaceInLine(line, oldKey, newKey string) (string, bool) { |