mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: CLI use multiselect for list(string) (#6631)
* feat: CLI use multiselect for list(string) * fix * select ui tests * cli test * Fix * Fix
This commit is contained in:
@@ -86,3 +86,36 @@ func newRichSelect(ptty *ptytest.PTY, opts cliui.RichSelectOptions) (string, err
|
||||
cmd.SetIn(ptty.Input())
|
||||
return value, cmd.ExecuteContext(context.Background())
|
||||
}
|
||||
|
||||
func TestMultiSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("MultiSelect", func(t *testing.T) {
|
||||
items := []string{"aaa", "bbb", "ccc"}
|
||||
|
||||
t.Parallel()
|
||||
ptty := ptytest.New(t)
|
||||
msgChan := make(chan []string)
|
||||
go func() {
|
||||
resp, err := newMultiSelect(ptty, items)
|
||||
assert.NoError(t, err)
|
||||
msgChan <- resp
|
||||
}()
|
||||
require.Equal(t, items, <-msgChan)
|
||||
})
|
||||
}
|
||||
|
||||
func newMultiSelect(ptty *ptytest.PTY, items []string) ([]string, error) {
|
||||
var values []string
|
||||
cmd := &cobra.Command{
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
selectedItems, err := cliui.MultiSelect(cmd, items)
|
||||
if err == nil {
|
||||
values = selectedItems
|
||||
}
|
||||
return err
|
||||
},
|
||||
}
|
||||
cmd.SetOutput(ptty.Output())
|
||||
cmd.SetIn(ptty.Input())
|
||||
return values, cmd.ExecuteContext(context.Background())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user