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
|
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||||
},
|
},
|
||||||
SilenceErrors: true,
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
runInteractiveMode()
|
runInteractiveMode()
|
||||||
|
|||||||
@@ -658,13 +658,34 @@ func AddSSHHostToFile(host SSHHost, configPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseSSHOptionsFromCommand converts SSH command line options to config format
|
// 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"
|
// Output: "Compression yes\nServerAliveInterval 60"
|
||||||
func ParseSSHOptionsFromCommand(options string) string {
|
func ParseSSHOptionsFromCommand(options string) string {
|
||||||
if options == "" {
|
if options == "" {
|
||||||
return ""
|
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
|
var result []string
|
||||||
parts := strings.Split(options, "-o")
|
parts := strings.Split(options, "-o")
|
||||||
|
|
||||||
@@ -690,6 +711,12 @@ func FormatSSHOptionsForCommand(options string) string {
|
|||||||
return ""
|
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
|
var result []string
|
||||||
lines := strings.Split(options, "\n")
|
lines := strings.Split(options, "\n")
|
||||||
|
|
||||||
|
|||||||
@@ -145,9 +145,9 @@ const (
|
|||||||
identityInput
|
identityInput
|
||||||
proxyJumpInput
|
proxyJumpInput
|
||||||
proxyCommandInput
|
proxyCommandInput
|
||||||
|
optionsInput
|
||||||
tagsInput
|
tagsInput
|
||||||
// Advanced tab inputs
|
// Advanced tab inputs
|
||||||
optionsInput
|
|
||||||
remoteCommandInput
|
remoteCommandInput
|
||||||
requestTTYInput
|
requestTTYInput
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ func (m *editFormModel) submitEditForm() tea.Cmd {
|
|||||||
identity := strings.TrimSpace(m.inputs[3].Value()) // identityInput
|
identity := strings.TrimSpace(m.inputs[3].Value()) // identityInput
|
||||||
proxyJump := strings.TrimSpace(m.inputs[4].Value()) // proxyJumpInput
|
proxyJump := strings.TrimSpace(m.inputs[4].Value()) // proxyJumpInput
|
||||||
proxyCommand := strings.TrimSpace(m.inputs[5].Value()) // proxyCommandInput
|
proxyCommand := strings.TrimSpace(m.inputs[5].Value()) // proxyCommandInput
|
||||||
options := strings.TrimSpace(m.inputs[6].Value()) // optionsInput
|
options := config.ParseSSHOptionsFromCommand(strings.TrimSpace(m.inputs[6].Value())) // optionsInput
|
||||||
remoteCommand := strings.TrimSpace(m.inputs[8].Value()) // remoteCommandInput
|
remoteCommand := strings.TrimSpace(m.inputs[8].Value()) // remoteCommandInput
|
||||||
requestTTY := strings.TrimSpace(m.inputs[9].Value()) // requestTTYInput
|
requestTTY := strings.TrimSpace(m.inputs[9].Value()) // requestTTYInput
|
||||||
|
|
||||||
@@ -714,7 +714,7 @@ func (m *editFormModel) submitEditForm() tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse tags
|
// Parse tags
|
||||||
tagsStr := strings.TrimSpace(m.inputs[6].Value()) // tagsInput
|
tagsStr := strings.TrimSpace(m.inputs[7].Value()) // tagsInput
|
||||||
var tags []string
|
var tags []string
|
||||||
if tagsStr != "" {
|
if tagsStr != "" {
|
||||||
for _, tag := range strings.Split(tagsStr, ",") {
|
for _, tag := range strings.Split(tagsStr, ",") {
|
||||||
|
|||||||
Reference in New Issue
Block a user