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

Function newPortsForwardCmd

pkg/cmd/codespace/ports.go:302–323  ·  view source on GitHub ↗

NewPortsForwardCmd returns a Cobra "ports forward" subcommand, which forwards a set of port pairs from the codespace to localhost.

(app *App, selector *CodespaceSelector)

Source from the content-addressed store, hash-verified

300// NewPortsForwardCmd returns a Cobra "ports forward" subcommand, which forwards a set of
301// port pairs from the codespace to localhost.
302func newPortsForwardCmd(app *App, selector *CodespaceSelector) *cobra.Command {
303 var allInterfaces bool
304
305 cmd := &cobra.Command{
306 Use: "forward <remote-port>:<local-port>...",
307 Short: "Forward ports",
308 Long: heredoc.Docf(`
309 Forward ports from a codespace to your local machine.
310
311 Ports bind to loopback (%[1]s127.0.0.1%[1]s) by default. Use %[1]s--all-interfaces%[1]s
312 to bind to all interfaces.
313 `, "`"),
314 Args: cobra.MinimumNArgs(1),
315 RunE: func(cmd *cobra.Command, args []string) error {
316 return app.ForwardPorts(cmd.Context(), selector, args, allInterfaces)
317 },
318 }
319
320 cmd.Flags().BoolVar(&allInterfaces, "all-interfaces", false, "Listen on all network interfaces")
321
322 return cmd
323}
324
325func (a *App) ForwardPorts(ctx context.Context, selector *CodespaceSelector, ports []string, allInterfaces bool) (err error) {
326 portPairs, err := getPortPairs(ports)

Callers 1

newPortsCmdFunction · 0.85

Calls 1

ForwardPortsMethod · 0.80

Tested by

no test coverage detected