Skip to content

Commit 6b5ddfa

Browse files
committed
feat: enhance copy SSH command with alias and tags metadata
- Update BuildSSHCommand to include alias and tags as comment - Format: # lazyssh-alias:<alias> tags:<tag1,tag2,...> - Add test coverage for BuildSSHCommand with tags - Enable round-trip capability (copy → paste preserves metadata)
1 parent d02b2c2 commit 6b5ddfa

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

internal/adapters/ui/utils.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ func humanizeDuration(t time.Time) string {
123123
// BuildSSHCommand constructs a ready-to-run ssh command for the given server.
124124
// Format: ssh [options] [user@]host [command]
125125
func BuildSSHCommand(s domain.Server) string {
126-
parts := []string{"ssh"}
126+
// Start with alias and tags comment for easy parsing when pasting
127+
comment := "# lazyssh-alias:" + s.Alias
128+
if len(s.Tags) > 0 {
129+
comment += " tags:" + strings.Join(s.Tags, ",")
130+
}
131+
parts := []string{comment, "\nssh"}
127132

128133
// Add proxy and connection options
129134
addProxyOptions(&parts, s)

internal/adapters/ui/utils_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ func TestBuildSSHCommand_PortForwarding(t *testing.T) {
115115
}
116116
}
117117

118-
// Additional check: ensure the command starts with "ssh"
119-
if !strings.HasPrefix(result, "ssh ") {
120-
t.Errorf("BuildSSHCommand() should start with 'ssh ', got: %q", result)
118+
// Additional check: ensure the command contains "ssh" command
119+
// Now it includes alias comment, so check for "\nssh " or just "ssh " at the beginning
120+
if !strings.Contains(result, "\nssh ") && !strings.HasPrefix(result, "ssh ") {
121+
t.Errorf("BuildSSHCommand() should contain 'ssh ' command, got: %q", result)
121122
}
122123
})
123124
}
@@ -129,6 +130,7 @@ func TestBuildSSHCommand_CompleteCommand(t *testing.T) {
129130
Host: "example.com",
130131
User: "admin",
131132
Port: 2222,
133+
Tags: []string{"production", "web"},
132134
LocalForward: []string{"8080:localhost:80", "3306:db.internal:3306"},
133135
RemoteForward: []string{"9090:localhost:9090"},
134136
DynamicForward: []string{"1080"},
@@ -138,8 +140,14 @@ func TestBuildSSHCommand_CompleteCommand(t *testing.T) {
138140
result := BuildSSHCommand(server)
139141

140142
// Check command structure
141-
if !strings.HasPrefix(result, "ssh ") {
142-
t.Errorf("Command should start with 'ssh ', got: %q", result)
143+
// Check for alias and tags comment
144+
if !strings.HasPrefix(result, "# lazyssh-alias:myserver tags:production,web") {
145+
t.Errorf("Command should start with alias and tags comment, got: %q", result)
146+
}
147+
148+
// Check command contains ssh (now with alias comment)
149+
if !strings.Contains(result, "\nssh ") {
150+
t.Errorf("Command should contain 'ssh ' after alias comment, got: %q", result)
143151
}
144152

145153
// Check port

0 commit comments

Comments
 (0)