(ctx context.Context, ch *cmdutil.Helper)
| 585 | } |
| 586 | |
| 587 | func orgNamePrompt(ctx context.Context, ch *cmdutil.Helper) (string, error) { |
| 588 | qs := []*survey.Question{ |
| 589 | { |
| 590 | Name: "name", |
| 591 | Prompt: &survey.Input{ |
| 592 | Message: "Enter an org name", |
| 593 | }, |
| 594 | Validate: func(v any) error { |
| 595 | // Validate org name doesn't exist already |
| 596 | name := v.(string) |
| 597 | if name == "" { |
| 598 | return fmt.Errorf("empty name") |
| 599 | } |
| 600 | |
| 601 | exists, err := orgExists(ctx, ch, name) |
| 602 | if err != nil { |
| 603 | return fmt.Errorf("failed to check org name: %w", err) |
| 604 | } |
| 605 | |
| 606 | if exists { |
| 607 | return fmt.Errorf("org with name %q already exists", name) |
| 608 | } |
| 609 | return nil |
| 610 | }, |
| 611 | }, |
| 612 | } |
| 613 | |
| 614 | name := "" |
| 615 | if err := survey.Ask(qs, &name); err != nil { |
| 616 | return "", err |
| 617 | } |
| 618 | |
| 619 | return name, nil |
| 620 | } |
| 621 | |
| 622 | func orgExists(ctx context.Context, ch *cmdutil.Helper, name string) (bool, error) { |
| 623 | c, err := ch.Client() |
no test coverage detected