(client *api.Client)
| 247 | } |
| 248 | |
| 249 | func RunConnectInteractiveSelect(client *api.Client) (string, error) { |
| 250 | ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) |
| 251 | defer stop() |
| 252 | |
| 253 | InitCommonStyles(os.Stdout) |
| 254 | |
| 255 | m := newConnectFetchModel(client) |
| 256 | p := tea.NewProgram( |
| 257 | m, |
| 258 | tea.WithContext(ctx), |
| 259 | tea.WithOutput(os.Stdout), |
| 260 | ) |
| 261 | |
| 262 | finalModel, err := p.Run() |
| 263 | if err != nil { |
| 264 | return "", fmt.Errorf("error running connect TUI: %w", err) |
| 265 | } |
| 266 | |
| 267 | result, ok := finalModel.(connectModel) |
| 268 | if !ok { |
| 269 | return "", fmt.Errorf("unexpected model type") |
| 270 | } |
| 271 | |
| 272 | if result.cancelled { |
| 273 | return "", ErrCancelled |
| 274 | } |
| 275 | if result.err != nil { |
| 276 | return "", result.err |
| 277 | } |
| 278 | if result.noInstances { |
| 279 | return "", ErrNoRunningInstances |
| 280 | } |
| 281 | if result.selected == "" { |
| 282 | return "", ErrCancelled |
| 283 | } |
| 284 | if result.displayToID != nil { |
| 285 | if id, ok := result.displayToID[result.selected]; ok { |
| 286 | return id, nil |
| 287 | } |
| 288 | } |
| 289 | return "", fmt.Errorf("failed to resolve selected instance") |
| 290 | } |
| 291 | |
| 292 | func RunConnectSelectWithInstances(instances []api.Instance) (string, error) { |
| 293 | ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) |
nothing calls this directly
no test coverage detected