(path string)
| 157 | } |
| 158 | |
| 159 | func includeDevSpaceConfig(path string) (string, error) { |
| 160 | var reader io.Reader |
| 161 | f, err := os.Open(path) |
| 162 | if err != nil { |
| 163 | if !os.IsNotExist(err) { |
| 164 | return "", err |
| 165 | } |
| 166 | |
| 167 | reader = strings.NewReader("") |
| 168 | } else { |
| 169 | reader = f |
| 170 | defer f.Close() |
| 171 | } |
| 172 | |
| 173 | configScanner := scanner.NewScanner(reader) |
| 174 | newLines := []string{} |
| 175 | startMarker := "# DevSpace Start" |
| 176 | for configScanner.Scan() { |
| 177 | text := configScanner.Text() |
| 178 | if strings.HasPrefix(text, startMarker) { |
| 179 | return "", nil |
| 180 | } |
| 181 | |
| 182 | newLines = append(newLines, text) |
| 183 | } |
| 184 | if configScanner.Err() != nil { |
| 185 | return "", errors.Wrap(err, "parse ssh config") |
| 186 | } |
| 187 | |
| 188 | // add new section |
| 189 | newLines = append(newLines, startMarker) |
| 190 | newLines = append(newLines, "Match all") |
| 191 | newLines = append(newLines, "Include devspace_config") |
| 192 | newLines = append(newLines, "# DevSpace End") |
| 193 | return strings.Join(newLines, "\n"), nil |
| 194 | } |
| 195 | |
| 196 | func addHost(path, host, port string) (string, error) { |
| 197 | var reader io.Reader |
no test coverage detected