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

Function newPortsForwardCmd

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

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

Callers 1

newPortsCmdFunction · 0.85

Calls 1

ForwardPortsMethod · 0.80

Tested by

no test coverage detected