MCPcopy Create free account
hub / github.com/Mister-leo/fssh / findHostBlock

Function findHostBlock

internal/sshconfig/writer.go:247–284  ·  view source on GitHub ↗

findHostBlock finds the line range of a host block Returns (start, end, found) where end is exclusive

(lines []string, hostName string)

Source from the content-addressed store, hash-verified

245// findHostBlock finds the line range of a host block
246// Returns (start, end, found) where end is exclusive
247func findHostBlock(lines []string, hostName string) (int, int, bool) {
248 inBlock := false
249 start := -1
250
251 for i := 0; i < len(lines); i++ {
252 line := strings.TrimSpace(lines[i])
253 lower := strings.ToLower(line)
254
255 if strings.HasPrefix(lower, "host ") {
256 hostParts := strings.Fields(line[5:])
257
258 // Check if this is our target host
259 isTarget := false
260 for _, h := range hostParts {
261 if h == hostName {
262 isTarget = true
263 break
264 }
265 }
266
267 if isTarget && !inBlock {
268 // Found start of target block
269 inBlock = true
270 start = i
271 } else if inBlock {
272 // Found next host block, end of target
273 return start, i, true
274 }
275 }
276 }
277
278 // If we found the start but no next host, block extends to EOF
279 if inBlock {
280 return start, len(lines), true
281 }
282
283 return -1, -1, false
284}
285
286// renderHostBlock converts HostConfig to SSH config format
287func renderHostBlock(cfg *HostConfig) string {

Callers 5

LoadGlobalConfigFunction · 0.85
WriteGlobalConfigFunction · 0.85
WriteHostConfigFunction · 0.85
DeleteHostConfigFunction · 0.85
LoadHostConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected