| 35 | } |
| 36 | |
| 37 | func (cs *CodespaceSelector) Select(ctx context.Context) (codespace *api.Codespace, err error) { |
| 38 | if cs.codespaceName != "" { |
| 39 | codespace, err = cs.api.GetCodespace(ctx, cs.codespaceName, true) |
| 40 | if err != nil { |
| 41 | return nil, fmt.Errorf("getting full codespace details: %w", err) |
| 42 | } |
| 43 | } else { |
| 44 | codespaces, err := cs.fetchCodespaces(ctx) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | |
| 49 | codespace, err = cs.chooseCodespace(ctx, codespaces) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if codespace.PendingOperation { |
| 56 | return nil, fmt.Errorf( |
| 57 | "codespace is disabled while it has a pending operation: %s", |
| 58 | codespace.PendingOperationDisabledReason, |
| 59 | ) |
| 60 | } |
| 61 | |
| 62 | return codespace, nil |
| 63 | } |
| 64 | |
| 65 | func (cs *CodespaceSelector) SelectName(ctx context.Context) (string, error) { |
| 66 | if cs.codespaceName != "" { |