Reduce complexity

This commit is contained in:
Viktor Liu
2025-07-02 20:43:17 +02:00
parent 4bbca28eb6
commit 96084e3a02
6 changed files with 321 additions and 228 deletions

View File

@@ -186,19 +186,9 @@ func parseCustomSSHFlags(args []string) ([]string, []string, []string) {
arg := args[i]
switch {
case strings.HasPrefix(arg, "-L"):
if arg == "-L" && i+1 < len(args) {
localForwardFlags = append(localForwardFlags, args[i+1])
i++
} else if len(arg) > 2 {
localForwardFlags = append(localForwardFlags, arg[2:])
}
localForwardFlags, i = parseForwardFlag(arg, args, i, localForwardFlags)
case strings.HasPrefix(arg, "-R"):
if arg == "-R" && i+1 < len(args) {
remoteForwardFlags = append(remoteForwardFlags, args[i+1])
i++
} else if len(arg) > 2 {
remoteForwardFlags = append(remoteForwardFlags, arg[2:])
}
remoteForwardFlags, i = parseForwardFlag(arg, args, i, remoteForwardFlags)
default:
filteredArgs = append(filteredArgs, arg)
}
@@ -207,6 +197,18 @@ func parseCustomSSHFlags(args []string) ([]string, []string, []string) {
return filteredArgs, localForwardFlags, remoteForwardFlags
}
func parseForwardFlag(arg string, args []string, i int, flags []string) ([]string, int) {
if arg == "-L" || arg == "-R" {
if i+1 < len(args) {
flags = append(flags, args[i+1])
i++
}
} else if len(arg) > 2 {
flags = append(flags, arg[2:])
}
return flags, i
}
// extractGlobalFlags parses global flags that were passed before 'ssh' command
func extractGlobalFlags(args []string) {
sshPos := findSSHCommandPosition(args)