fix(cli): honor default selection in multi-select
All checks were successful
Security Scan / security (push) Successful in 22s

This commit is contained in:
Virgil 2026-04-02 06:15:59 +00:00
parent 43d4bbd2dc
commit e96ea6d7c2
2 changed files with 11 additions and 0 deletions

View file

@ -165,6 +165,14 @@ func TestChooseMulti_Good_CommasAndRanges(t *testing.T) {
assert.Equal(t, []string{"a", "b", "d"}, vals)
}
func TestChooseMulti_Good_DefaultIndex(t *testing.T) {
SetStdin(strings.NewReader("\n"))
defer SetStdin(nil)
vals := ChooseMulti("Pick", []string{"a", "b", "c"}, WithDefaultIndex[string](1))
assert.Equal(t, []string{"b"}, vals)
}
func TestSetStdin_Good_ResetNil(t *testing.T) {
original := stdin
t.Cleanup(func() { stdin = original })

View file

@ -441,6 +441,9 @@ func ChooseMulti[T any](prompt string, items []T, opts ...ChooseOption[T]) []T {
// Empty response returns no selections
if response == "" {
if cfg.defaultN >= 0 {
return []T{items[defaultVisibleIndex(visible, cfg.defaultN)]}
}
return nil
}