newPortsCmd returns a Cobra "ports" command that displays a table of available ports, according to the specified flags.
(app *App)
| 25 | // newPortsCmd returns a Cobra "ports" command that displays a table of available ports, |
| 26 | // according to the specified flags. |
| 27 | func newPortsCmd(app *App) *cobra.Command { |
| 28 | var ( |
| 29 | selector *CodespaceSelector |
| 30 | exporter cmdutil.Exporter |
| 31 | ) |
| 32 | |
| 33 | portsCmd := &cobra.Command{ |
| 34 | Use: "ports", |
| 35 | Short: "List ports in a codespace", |
| 36 | Args: noArgsConstraint, |
| 37 | RunE: func(cmd *cobra.Command, args []string) error { |
| 38 | return app.ListPorts(cmd.Context(), selector, exporter) |
| 39 | }, |
| 40 | } |
| 41 | |
| 42 | selector = AddCodespaceSelector(portsCmd, app.apiClient) |
| 43 | |
| 44 | cmdutil.AddJSONFlags(portsCmd, &exporter, portFields) |
| 45 | |
| 46 | portsCmd.AddCommand(newPortsForwardCmd(app, selector)) |
| 47 | portsCmd.AddCommand(newPortsVisibilityCmd(app, selector)) |
| 48 | |
| 49 | return portsCmd |
| 50 | } |
| 51 | |
| 52 | // ListPorts lists known ports in a codespace. |
| 53 | func (a *App) ListPorts(ctx context.Context, selector *CodespaceSelector, exporter cmdutil.Exporter) (err error) { |
no test coverage detected