| 491 | } |
| 492 | |
| 493 | func (cmd *LoginCommand) promptChosenSpace(spaces []resources.Space) (resources.Space, error) { |
| 494 | spaceNames := make([]string, len(spaces)) |
| 495 | for i, space := range spaces { |
| 496 | spaceNames[i] = space.Name |
| 497 | } |
| 498 | |
| 499 | chosenSpaceName, err := cmd.promptMenu(spaceNames, "Select a space:", "Space") |
| 500 | if err != nil { |
| 501 | if invalidChoice, ok := err.(ui.InvalidChoiceError); ok { |
| 502 | return resources.Space{}, translatableerror.SpaceNotFoundError{Name: invalidChoice.Choice} |
| 503 | } |
| 504 | |
| 505 | if err == io.EOF { |
| 506 | return resources.Space{}, nil |
| 507 | } |
| 508 | |
| 509 | return resources.Space{}, err |
| 510 | } |
| 511 | |
| 512 | for _, space := range spaces { |
| 513 | if space.Name == chosenSpaceName { |
| 514 | return space, nil |
| 515 | } |
| 516 | } |
| 517 | return resources.Space{}, nil |
| 518 | } |
| 519 | |
| 520 | func (cmd *LoginCommand) promptMenu(choices []string, text string, prompt string) (string, error) { |
| 521 | var choice string |