| 663 | } |
| 664 | |
| 665 | func (c *cli) customDomainNamePickerOptions(ctx context.Context) (pickerOptions, error) { |
| 666 | var opts pickerOptions |
| 667 | |
| 668 | domains, err := c.api.CustomDomain.List(ctx) |
| 669 | if err != nil { |
| 670 | var errStatus management.Error |
| 671 | errors.As(err, &errStatus) |
| 672 | // 403 is a valid response for free tenants that don't have |
| 673 | // custom domains enabled. |
| 674 | if errStatus != nil && errStatus.Status() == 403 { |
| 675 | return nil, errNoCustomDomains |
| 676 | } |
| 677 | |
| 678 | return nil, fmt.Errorf("failed to list custom domains: %w", err) |
| 679 | } |
| 680 | |
| 681 | for _, d := range domains { |
| 682 | domain := d.GetDomain() |
| 683 | label := fmt.Sprintf("%s %s", domain, ansi.Faint("("+d.GetID()+")")) |
| 684 | opts = append(opts, pickerOption{value: domain, label: label}) |
| 685 | } |
| 686 | |
| 687 | if len(opts) == 0 { |
| 688 | return nil, errNoCustomDomains |
| 689 | } |
| 690 | |
| 691 | return opts, nil |
| 692 | } |