feat: Go SSH interactive shell default, --native flag for system SSH

This commit is contained in:
swanadiva
2026-06-23 14:26:58 +07:00
parent 513492e6ee
commit b3878de9af
5 changed files with 99 additions and 12 deletions
+13 -11
View File
@@ -19,14 +19,14 @@ import (
var (
connectTimeout int
connectDirect bool
connectNative bool
)
// connectCmd represents the connect command
var connectCmd = &cobra.Command{
Use: "connect <host-name-or-id>",
Short: "Connect to a saved SSH host",
Long: `Connect to a saved SSH host using native SSH client with stored credentials.
Long: `Connect to a saved SSH host using stored credentials.
Examples:
# Connect to a host by name
@@ -35,15 +35,15 @@ Examples:
# Connect with a specific timeout
hostkeeper connect myserver --timeout 60
# Use Go SSH client (direct mode) instead of system SSH
hostkeeper connect myserver --direct`,
# Use native system SSH instead of Go SSH client
hostkeeper connect myserver --native`,
Args: cobra.ExactArgs(1),
RunE: runConnect,
}
func init() {
connectCmd.Flags().IntVar(&connectTimeout, "timeout", 30, "Connection timeout in seconds")
connectCmd.Flags().BoolVar(&connectDirect, "direct", false, "Use direct SSH instead of native client")
connectCmd.Flags().BoolVar(&connectNative, "native", false, "Use native system SSH instead of Go SSH client")
rootCmd.AddCommand(connectCmd)
}
@@ -77,11 +77,11 @@ func runConnect(cmd *cobra.Command, args []string) error {
fmt.Printf("Connecting to %s (%s@%s:%d)...\n", host.Name, host.Username, host.Hostname, host.Port)
// Choose connection method
if connectDirect {
return connectDirectSSH(host)
if connectNative {
return connectWithNativeSSH(host)
}
return connectWithNativeSSH(host)
return connectDirectSSH(host)
}
// findHost finds a host by ID first, then by name
@@ -156,9 +156,11 @@ func connectDirectSSH(host *models.Host) error {
}
defer client.Close()
fmt.Printf("Connected to %s\n", host.Name)
fmt.Println("Interactive shell not yet implemented in direct mode")
fmt.Println("Use --direct=false (default) for native SSH experience")
fmt.Printf("Connected to %s (%s@%s:%d)\n", host.Name, host.Username, host.Hostname, host.Port)
if err := client.Shell(); err != nil {
return fmt.Errorf("shell session failed: %w", err)
}
return nil
}