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:
Marcin Tojek
2023-03-16 17:17:48 +01:00
committed by GitHub
parent 95177ad0e5
commit 1f9ae15409
6 changed files with 199 additions and 6 deletions
+33
View File
@@ -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())
}