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

Function getPortPairs

pkg/cmd/codespace/ports.go:372–395  ·  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

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

Callers 1

ForwardPortsMethod · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected