MCPcopy Index your code
hub / github.com/cli/cli / getPortPairs

Function getPortPairs

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

358
359// getPortPairs parses a list of strings of form "%d:%d" into pairs of (remote, local) numbers.
360func getPortPairs(ports []string) ([]portPair, error) {
361 pp := make([]portPair, 0, len(ports))
362
363 for _, portString := range ports {
364 parts := strings.Split(portString, ":")
365 if len(parts) < 2 {
366 return nil, fmt.Errorf("port pair: %q is not valid", portString)
367 }
368
369 remote, err := strconv.Atoi(parts[0])
370 if err != nil {
371 return pp, fmt.Errorf("convert remote port to int: %w", err)
372 }
373
374 local, err := strconv.Atoi(parts[1])
375 if err != nil {
376 return pp, fmt.Errorf("convert local port to int: %w", err)
377 }
378
379 pp = append(pp, portPair{remote, local})
380 }
381
382 return pp, nil
383}
384
385func normalizeJSON(j []byte) []byte {
386 // remove trailing commas

Callers 1

ForwardPortsMethod · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected