-
Notifications
You must be signed in to change notification settings - Fork 875
feat: allow entering non-default values in multi-select #15935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -101,6 +101,39 @@ func TestMultiSelect(t *testing.T) { | |||
}() | ||||
require.Equal(t, items, <-msgChan) | ||||
}) | ||||
|
||||
t.Run("MultiSelectWithCustomInput", func(t *testing.T) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. couldn't add tests to check the custom input flow, we had this check here and not sure if its safe to remove and add interactive tests, please do let me know if there's a better way to incorporate those tests Line 310 in 63572d9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think historically we've manually tested this using |
||||
t.Parallel() | ||||
items := []string{"Code", "Chairs", "Whale", "Diamond", "Carrot"} | ||||
ptty := ptytest.New(t) | ||||
msgChan := make(chan []string) | ||||
go func() { | ||||
resp, err := newMultiSelectWithCustomInput(ptty, items) | ||||
assert.NoError(t, err) | ||||
msgChan <- resp | ||||
}() | ||||
require.Equal(t, items, <-msgChan) | ||||
}) | ||||
} | ||||
|
||||
func newMultiSelectWithCustomInput(ptty *ptytest.PTY, items []string) ([]string, error) { | ||||
var values []string | ||||
cmd := &serpent.Command{ | ||||
Handler: func(inv *serpent.Invocation) error { | ||||
selectedItems, err := cliui.MultiSelect(inv, cliui.MultiSelectOptions{ | ||||
Options: items, | ||||
Defaults: items, | ||||
EnableCustomInput: true, | ||||
}) | ||||
if err == nil { | ||||
values = selectedItems | ||||
} | ||||
return err | ||||
}, | ||||
} | ||||
inv := cmd.Invoke() | ||||
ptty.Attach(inv) | ||||
return values, inv.Run() | ||||
} | ||||
|
||||
func newMultiSelect(ptty *ptytest.PTY, items []string) ([]string, error) { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic needs to handle when
EnableCustomInput
is false. Currently it lets you go over the last valid option.