(fileName string, targetLines []int)
| 1105 | } |
| 1106 | |
| 1107 | func commentSSHConfigLines(fileName string, targetLines []int) error { |
| 1108 | content, err := os.ReadFile(fileName) |
| 1109 | if err != nil { |
| 1110 | return err |
| 1111 | } |
| 1112 | lines := strings.Split(string(content), "\n") |
| 1113 | targetSet := make(map[int]struct{}, len(targetLines)) |
| 1114 | for _, line := range targetLines { |
| 1115 | targetSet[line] = struct{}{} |
| 1116 | } |
| 1117 | for index := range lines { |
| 1118 | if _, ok := targetSet[index]; !ok { |
| 1119 | continue |
| 1120 | } |
| 1121 | trimmed := strings.TrimSpace(lines[index]) |
| 1122 | if trimmed == "" || strings.HasPrefix(trimmed, "#") { |
| 1123 | continue |
| 1124 | } |
| 1125 | lines[index] = "#" + lines[index] |
| 1126 | } |
| 1127 | return os.WriteFile(fileName, []byte(strings.Join(lines, "\n")), constant.FilePerm) |
| 1128 | } |
| 1129 | |
| 1130 | func loadSSHInsertIndex(lines []string) int { |
| 1131 | for index, line := range lines { |
no test coverage detected