@@ -46,7 +46,7 @@ func newPortsCmd(app *App) *cobra.Command {
4646
4747// ListPorts lists known ports in a codespace.
4848func (a * App ) ListPorts (ctx context.Context , codespaceName string , exporter cmdutil.Exporter ) (err error ) {
49- codespace , err := getCodespaceForPorts (ctx , a .apiClient , codespaceName )
49+ codespace , err := getOrChooseCodespace (ctx , a .apiClient , codespaceName )
5050 if err != nil {
5151 return err
5252 }
@@ -231,7 +231,7 @@ func (a *App) UpdatePortVisibility(ctx context.Context, codespaceName string, ar
231231 return fmt .Errorf ("error parsing port arguments: %w" , err )
232232 }
233233
234- codespace , err := getCodespaceForPorts (ctx , a .apiClient , codespaceName )
234+ codespace , err := getOrChooseCodespace (ctx , a .apiClient , codespaceName )
235235 if err != nil {
236236 return err
237237 }
@@ -304,7 +304,7 @@ func (a *App) ForwardPorts(ctx context.Context, codespaceName string, ports []st
304304 return fmt .Errorf ("get port pairs: %w" , err )
305305 }
306306
307- codespace , err := getCodespaceForPorts (ctx , a .apiClient , codespaceName )
307+ codespace , err := getOrChooseCodespace (ctx , a .apiClient , codespaceName )
308308 if err != nil {
309309 return err
310310 }
@@ -370,23 +370,3 @@ func normalizeJSON(j []byte) []byte {
370370 // remove trailing commas
371371 return bytes .ReplaceAll (j , []byte ("},}" ), []byte ("}}" ))
372372}
373-
374- func getCodespaceForPorts (ctx context.Context , apiClient apiClient , codespaceName string ) (* api.Codespace , error ) {
375- codespace , err := getOrChooseCodespace (ctx , apiClient , codespaceName )
376- if err != nil {
377- // TODO(josebalius): remove special handling of this error here and it other places
378- if err == errNoCodespaces {
379- return nil , err
380- }
381- return nil , fmt .Errorf ("error choosing codespace: %w" , err )
382- }
383-
384- if codespace .PendingOperation {
385- return nil , fmt .Errorf (
386- "codespace is disabled while it has a pending operation: %s" ,
387- codespace .PendingOperationDisabledReason ,
388- )
389- }
390-
391- return codespace , nil
392- }
0 commit comments