| 460 | } |
| 461 | |
| 462 | func (cmd *LoginCommand) promptChosenOrg(orgs []resources.Organization) (resources.Organization, error) { |
| 463 | orgNames := make([]string, len(orgs)) |
| 464 | for i, org := range orgs { |
| 465 | orgNames[i] = org.Name |
| 466 | } |
| 467 | |
| 468 | chosenOrgName, err := cmd.promptMenu(orgNames, "Select an org:", "Org") |
| 469 | if err != nil { |
| 470 | if invalidChoice, ok := err.(ui.InvalidChoiceError); ok { |
| 471 | if cmd.Space != "" { |
| 472 | return resources.Organization{}, translatableerror.OrganizationWithSpaceNotFoundError{Name: invalidChoice.Choice, SpaceName: cmd.Space} |
| 473 | } |
| 474 | return resources.Organization{}, translatableerror.OrganizationNotFoundError{Name: invalidChoice.Choice} |
| 475 | } |
| 476 | |
| 477 | if err == io.EOF { |
| 478 | return resources.Organization{}, nil |
| 479 | } |
| 480 | |
| 481 | return resources.Organization{}, err |
| 482 | } |
| 483 | |
| 484 | for _, org := range orgs { |
| 485 | if org.Name == chosenOrgName { |
| 486 | return org, nil |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | return resources.Organization{}, nil |
| 491 | } |
| 492 | |
| 493 | func (cmd *LoginCommand) promptChosenSpace(spaces []resources.Space) (resources.Space, error) { |
| 494 | spaceNames := make([]string, len(spaces)) |