runProviderWizard is the entry point called from provider_cmd.go.
( out io.Writer, stdin io.Reader, mode wizardMode, existing *providers.Endpoint, existingName string, existingNames []string, )
| 334 | |
| 335 | // runProviderWizard is the entry point called from provider_cmd.go. |
| 336 | func runProviderWizard( |
| 337 | out io.Writer, |
| 338 | stdin io.Reader, |
| 339 | mode wizardMode, |
| 340 | existing *providers.Endpoint, |
| 341 | existingName string, |
| 342 | existingNames []string, |
| 343 | ) (name string, ep providers.Endpoint, cancelled bool, err error) { |
| 344 | file, ok := stdin.(*os.File) |
| 345 | if !ok || !isTerminal(file) { |
| 346 | hint := "cam provider add NAME --endpoint URL [--api-key-env VAR] ..." |
| 347 | if mode == wizardModeUpdate { |
| 348 | hint = "cam provider update NAME --endpoint URL [--description TEXT] ..." |
| 349 | } |
| 350 | return "", providers.Endpoint{}, false, |
| 351 | fmt.Errorf("interactive wizard requires a terminal; use flags instead:\n %s", hint) |
| 352 | } |
| 353 | |
| 354 | model := newProviderWizardModel(mode, existing, existingName, existingNames) |
| 355 | program := tea.NewProgram(model, tea.WithOutput(out)) |
| 356 | final, err := program.Run() |
| 357 | if err != nil { |
| 358 | return "", providers.Endpoint{}, false, err |
| 359 | } |
| 360 | |
| 361 | wizard, ok := final.(providerWizardModel) |
| 362 | if !ok || wizard.aborted { |
| 363 | return "", providers.Endpoint{}, true, nil |
| 364 | } |
| 365 | |
| 366 | n, e := wizard.result() |
| 367 | return n, e, false, nil |
| 368 | } |
no test coverage detected