mirror of
https://github.com/Gu1llaum-3/sshm.git
synced 2026-01-27 03:04:21 +01:00
fix: correct field mapping in forms and prevent double -o prefix in SSH options
This commit is contained in:
@@ -85,7 +85,6 @@ Examples:
|
||||
|
||||
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
runInteractiveMode()
|
||||
|
||||
@@ -658,13 +658,34 @@ func AddSSHHostToFile(host SSHHost, configPath string) error {
|
||||
}
|
||||
|
||||
// ParseSSHOptionsFromCommand converts SSH command line options to config format
|
||||
// Input: "-o Compression=yes -o ServerAliveInterval=60"
|
||||
// Input: "-o Compression=yes -o ServerAliveInterval=60" or "ForwardX11 true" or "Compression yes"
|
||||
// Output: "Compression yes\nServerAliveInterval 60"
|
||||
func ParseSSHOptionsFromCommand(options string) string {
|
||||
if options == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
options = strings.TrimSpace(options)
|
||||
|
||||
// If it doesn't contain -o, assume it's already in config format
|
||||
if !strings.Contains(options, "-o") {
|
||||
// Just normalize spaces and ensure newlines between options
|
||||
lines := strings.Split(options, "\n")
|
||||
var result []string
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
// Normalize spacing (replace multiple spaces with single space)
|
||||
parts := strings.Fields(line)
|
||||
if len(parts) > 0 {
|
||||
result = append(result, strings.Join(parts, " "))
|
||||
}
|
||||
}
|
||||
return strings.Join(result, "\n")
|
||||
}
|
||||
|
||||
var result []string
|
||||
parts := strings.Split(options, "-o")
|
||||
|
||||
@@ -690,6 +711,12 @@ func FormatSSHOptionsForCommand(options string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// If already in command format (starts with -o), return as is
|
||||
trimmed := strings.TrimSpace(options)
|
||||
if strings.HasPrefix(trimmed, "-o ") {
|
||||
return trimmed
|
||||
}
|
||||
|
||||
var result []string
|
||||
lines := strings.Split(options, "\n")
|
||||
|
||||
|
||||
@@ -145,9 +145,9 @@ const (
|
||||
identityInput
|
||||
proxyJumpInput
|
||||
proxyCommandInput
|
||||
optionsInput
|
||||
tagsInput
|
||||
// Advanced tab inputs
|
||||
optionsInput
|
||||
remoteCommandInput
|
||||
requestTTYInput
|
||||
)
|
||||
|
||||
@@ -686,15 +686,15 @@ func (m *editFormModel) submitEditForm() tea.Cmd {
|
||||
}
|
||||
|
||||
// Get property values using direct indices
|
||||
hostname := strings.TrimSpace(m.inputs[0].Value()) // hostnameInput
|
||||
user := strings.TrimSpace(m.inputs[1].Value()) // userInput
|
||||
port := strings.TrimSpace(m.inputs[2].Value()) // portInput
|
||||
identity := strings.TrimSpace(m.inputs[3].Value()) // identityInput
|
||||
proxyJump := strings.TrimSpace(m.inputs[4].Value()) // proxyJumpInput
|
||||
proxyCommand := strings.TrimSpace(m.inputs[5].Value()) // proxyCommandInput
|
||||
options := strings.TrimSpace(m.inputs[6].Value()) // optionsInput
|
||||
remoteCommand := strings.TrimSpace(m.inputs[8].Value()) // remoteCommandInput
|
||||
requestTTY := strings.TrimSpace(m.inputs[9].Value()) // requestTTYInput
|
||||
hostname := strings.TrimSpace(m.inputs[0].Value()) // hostnameInput
|
||||
user := strings.TrimSpace(m.inputs[1].Value()) // userInput
|
||||
port := strings.TrimSpace(m.inputs[2].Value()) // portInput
|
||||
identity := strings.TrimSpace(m.inputs[3].Value()) // identityInput
|
||||
proxyJump := strings.TrimSpace(m.inputs[4].Value()) // proxyJumpInput
|
||||
proxyCommand := strings.TrimSpace(m.inputs[5].Value()) // proxyCommandInput
|
||||
options := config.ParseSSHOptionsFromCommand(strings.TrimSpace(m.inputs[6].Value())) // optionsInput
|
||||
remoteCommand := strings.TrimSpace(m.inputs[8].Value()) // remoteCommandInput
|
||||
requestTTY := strings.TrimSpace(m.inputs[9].Value()) // requestTTYInput
|
||||
|
||||
// Set defaults
|
||||
if port == "" {
|
||||
@@ -714,7 +714,7 @@ func (m *editFormModel) submitEditForm() tea.Cmd {
|
||||
}
|
||||
|
||||
// Parse tags
|
||||
tagsStr := strings.TrimSpace(m.inputs[6].Value()) // tagsInput
|
||||
tagsStr := strings.TrimSpace(m.inputs[7].Value()) // tagsInput
|
||||
var tags []string
|
||||
if tagsStr != "" {
|
||||
for _, tag := range strings.Split(tagsStr, ",") {
|
||||
|
||||
Reference in New Issue
Block a user