MCPcopy Create free account
hub / github.com/cli/cli / getPortPairs

Function getPortPairs

pkg/cmd/codespace/ports.go:373–396  ·  view source on GitHub ↗

getPortPairs parses a list of strings of form "%d:%d" into pairs of (remote, local) numbers.

(ports []string)

Source from the content-addressed store, hash-verified

371
372// getPortPairs parses a list of strings of form "%d:%d" into pairs of (remote, local) numbers.
373func getPortPairs(ports []string) ([]portPair, error) {
374 pp := make([]portPair, 0, len(ports))
375
376 for _, portString := range ports {
377 parts := strings.Split(portString, ":")
378 if len(parts) < 2 {
379 return nil, fmt.Errorf("port pair: %q is not valid", portString)
380 }
381
382 remote, err := strconv.Atoi(parts[0])
383 if err != nil {
384 return pp, fmt.Errorf("convert remote port to int: %w", err)
385 }
386
387 local, err := strconv.Atoi(parts[1])
388 if err != nil {
389 return pp, fmt.Errorf("convert local port to int: %w", err)
390 }
391
392 pp = append(pp, portPair{remote, local})
393 }
394
395 return pp, nil
396}
397
398func normalizeJSON(j []byte) []byte {
399 // remove trailing commas

Callers 1

ForwardPortsMethod · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected