Skip to content

Commit

Permalink
Remove index for list selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharath Joginapally authored and Bharath Joginapally committed Nov 18, 2022
1 parent f4628aa commit 320c01b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/prompt/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (e *ErrUnsupportedModel) Error() string {
return "invalid model for prompt operation"
}

// Is checks for the error type is ErrUnsupportedModel.
// Is checks if the error provided is of type ErrUnsupportedModel.
func (e *ErrUnsupportedModel) Is(target error) bool {
t, ok := target.(*ErrUnsupportedModel)
if !ok {
Expand Down
8 changes: 3 additions & 5 deletions pkg/cli/prompt/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ func NewListModel(choices []string, promptMsg string) ListModel {

// ListMode represents the bubble tea model to use for user input
type ListModel struct {
List list.Model
Choice string
ChoiceIndex int
Quitting bool
List list.Model
Choice string
Quitting bool
}

// Init used for creating an inital tea command if needed.
Expand All @@ -109,7 +108,6 @@ func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
i, ok := m.List.SelectedItem().(item)
if ok {
m.Choice = string(i)
m.ChoiceIndex = m.List.Index()
}
return m, tea.Quit
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/cli/prompt/mock_bubleteaprompter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/cli/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type BubbleTeaPrompter interface {
GetTextInput(promptMsg string) (string, error)

// GetListInput prompts user to select from a list
GetListInput(items []string, promptMsg string) (int, string, error)
GetListInput(items []string, promptMsg string) (string, error)
}

// BubbleTeaPrompterImpl implements BubbleTeaPrompter
Expand All @@ -266,17 +266,17 @@ func (i *BubbleTeaPrompterImpl) GetTextInput(promptMsg string) (string, error) {
}

// GetListInput prompts user to select from a list
func (i *BubbleTeaPrompterImpl) GetListInput(items []string, promptMsg string) (int, string, error) {
func (i *BubbleTeaPrompterImpl) GetListInput(items []string, promptMsg string) (string, error) {
lm := cli_list.NewListModel(items, promptMsg)
model, err := tea.NewProgram(lm).Run()
if err != nil {
return -1, "", err
return "", err
}

lm, ok := model.(cli_list.ListModel)
if !ok {
return -1, "", &ErrUnsupportedModel{}
return "", &ErrUnsupportedModel{}
}

return lm.ChoiceIndex, lm.Choice, nil
return lm.Choice, nil
}

0 comments on commit 320c01b

Please sign in to comment.