ab7317b0c0
7 funciones Go del dominio infra para gestion programatica de ~/.ssh/config: ssh_config_parse (parser de bloques Host/Match), ssh_config_read (lectura del archivo), ssh_config_find (busqueda por host), ssh_config_add_entry y ssh_config_remove_entry (CRUD), ssh_config_render (serializacion a texto), ssh_config_write (escritura atomica). Incluye tipo SshConfigEntry (product type) y tests unitarios del parser.
17 lines
506 B
Go
17 lines
506 B
Go
package infra
|
|
|
|
import "fmt"
|
|
|
|
// SSHConfigAddEntry añade un nuevo entry a la lista. Retorna error si el alias
|
|
// ya existe. No muta el slice original.
|
|
func SSHConfigAddEntry(entries []SSHConfigEntry, entry SSHConfigEntry) ([]SSHConfigEntry, error) {
|
|
for _, e := range entries {
|
|
if e.Alias == entry.Alias {
|
|
return nil, fmt.Errorf("alias %q already exists", entry.Alias)
|
|
}
|
|
}
|
|
result := make([]SSHConfigEntry, len(entries), len(entries)+1)
|
|
copy(result, entries)
|
|
return append(result, entry), nil
|
|
}
|