MCPcopy
hub / github.com/cloudfoundry/cli / promptChosenSpace

Method promptChosenSpace

command/v7/login_command.go:493–518  ·  view source on GitHub ↗
(spaces []resources.Space)

Source from the content-addressed store, hash-verified

491}
492
493func (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
520func (cmd *LoginCommand) promptMenu(choices []string, text string, prompt string) (string, error) {
521 var choice string

Callers 1

ExecuteMethod · 0.95

Calls 1

promptMenuMethod · 0.95

Tested by

no test coverage detected