Skip to content

Commit b7fb586

Browse files
authored
feat(parser): refactor ssh_config parser and writer to preserve unmanaged fields, comments, and directives (#45)
This PR introduces a major refactor of the SSH config parsing and writing logic. The new implementation is more robust and secure, ensuring that only the intended changes are applied while preserving the original file’s structure. Key changes - Lossless parsing/writing: Preserve unmanaged fields (e.g., `ProxyJump`), comments, and directives such as `Include` and `Match`. - Library update: Switched to [github.com/kevinburke/ssh_config](https://github.com/kevinburke/ssh_config) as the base parser, with a custom fork to support required modifications https://github.com/adembc/ssh_config. - Backup policy: Before any modification, create a backup of the SSH config file. Maintain up to 10 backups (configurable in the future) and automatically delete older ones. - IdentityFile handling: Parse IdentityFile as an array instead of a single string, with improved update logic. - Bug fix: Resolve issue where tags could not be fully removed. - Multiple aliases: Support defining and managing multiple aliases for a single server. - Testability: Code has been refactored with testability in mind. Follow-up PRs will include dedicated tests.
1 parent 78c660d commit b7fb586

23 files changed

+896
-740
lines changed

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"os"
2020
"path/filepath"
2121

22-
"github.com/Adembc/lazyssh/internal/adapters/data/file"
22+
"github.com/Adembc/lazyssh/internal/adapters/data/ssh_config_file"
2323
"github.com/Adembc/lazyssh/internal/logger"
2424

2525
"github.com/Adembc/lazyssh/internal/adapters/ui"
@@ -51,7 +51,7 @@ func main() {
5151
sshConfigFile := filepath.Join(home, ".ssh", "config")
5252
metaDataFile := filepath.Join(home, ".lazyssh", "metadata.json")
5353

54-
serverRepo := file.NewServerRepo(log, sshConfigFile, metaDataFile)
54+
serverRepo := ssh_config_file.NewRepository(log, sshConfigFile, metaDataFile)
5555
serverService := services.NewServerService(log, serverRepo)
5656
tui := ui.NewTUI(log, serverService, version, gitCommit)
5757

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ module github.com/Adembc/lazyssh
22

33
go 1.24.6
44

5+
replace github.com/kevinburke/ssh_config => github.com/adembc/ssh_config v1.4.2
6+
57
require (
68
github.com/atotto/clipboard v0.1.4
79
github.com/gdamore/tcell/v2 v2.9.0
10+
github.com/kevinburke/ssh_config v1.4.0
811
github.com/mattn/go-runewidth v0.0.16
912
github.com/rivo/tview v0.0.0-20250625164341-a4a78f1e05cb
1013
github.com/spf13/cobra v1.9.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/adembc/ssh_config v1.4.2 h1:Q0GMGDTvddd9QqdCri/M6SoBzPhmc1gjsXXEc9wpHTM=
2+
github.com/adembc/ssh_config v1.4.2/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
13
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
24
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
35
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=

internal/adapters/data/file/parser.go

Lines changed: 0 additions & 119 deletions
This file was deleted.

internal/adapters/data/file/server_repo.go

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)