(arg string)
| 66 | } |
| 67 | |
| 68 | func (o *SSHOptions) parseLocalForwardingSpec(arg string) (*ForwardSpec, error) { |
| 69 | arg = strings.TrimSpace(arg) |
| 70 | |
| 71 | parts := []string{} |
| 72 | for remainder := arg; remainder != ""; { |
| 73 | part, r, err := tokenizeForward(remainder) |
| 74 | if err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | |
| 78 | parts = append(parts, part) |
| 79 | remainder = r |
| 80 | } |
| 81 | |
| 82 | forwardSpec := &ForwardSpec{} |
| 83 | switch len(parts) { |
| 84 | case 4: |
| 85 | if parts[0] == "*" { |
| 86 | parts[0] = "" |
| 87 | } |
| 88 | forwardSpec.ListenAddress = fmt.Sprintf("%s:%s", parts[0], parts[1]) |
| 89 | forwardSpec.ConnectAddress = fmt.Sprintf("%s:%s", parts[2], parts[3]) |
| 90 | case 3: |
| 91 | forwardSpec.ListenAddress = fmt.Sprintf("localhost:%s", parts[0]) |
| 92 | forwardSpec.ConnectAddress = fmt.Sprintf("%s:%s", parts[1], parts[2]) |
| 93 | default: |
| 94 | return nil, fmt.Errorf("Unable to parse local forwarding argument: %q", arg) |
| 95 | } |
| 96 | |
| 97 | return forwardSpec, nil |
| 98 | } |
| 99 | |
| 100 | func tokenizeForward(arg string) (string, string, error) { |
| 101 | switch arg[0] { |
no test coverage detected