func addCommentsToLines()

in gke-deploy/core/resource/resource.go [204:223]


func addCommentsToLines(s string, lineComments map[string]string) (string, error) {
	lines := strings.Split(s, "\n")
	lineIdx := 0
	for _, line := range lines {
		for stringToContain, comment := range lineComments {
			if strings.Contains(stringToContain, "\n") {
				return "", fmt.Errorf("line cannot contain a newline character")
			}
			if strings.Contains(comment, "\n") {
				return "", fmt.Errorf("comment cannot contain a newline character")
			}
			if strings.Contains(line, stringToContain) {
				lines[lineIdx] = fmt.Sprintf("%s  # %s", line, comment)
			}
		}
		lineIdx++
	}

	return strings.Join(lines, "\n"), nil
}