MCPcopy Index your code
hub / github.com/cloudfoundry/cli / parseLocalForwardingSpec

Method parseLocalForwardingSpec

cf/ssh/options/ssh_options.go:68–98  ·  view source on GitHub ↗
(arg string)

Source from the content-addressed store, hash-verified

66}
67
68func (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
100func tokenizeForward(arg string) (string, string, error) {
101 switch arg[0] {

Callers 1

NewSSHOptionsFunction · 0.95

Calls 1

tokenizeForwardFunction · 0.85

Tested by

no test coverage detected